diff --git a/InterfaceGenerator/InterfaceGenerator.cs b/InterfaceGenerator/InterfaceGenerator.cs index 32d4688..b475a82 100644 --- a/InterfaceGenerator/InterfaceGenerator.cs +++ b/InterfaceGenerator/InterfaceGenerator.cs @@ -102,25 +102,25 @@ SemanticModel semanticModel .OfType() .Where(p => p.DeclaredAccessibility == Accessibility.Public) .Select( - p => p.ToDisplayString(Constants.SymbolDisplayFormat) - // PropertyDeclarationTemplate.Render( - // new PropertyDeclarationModel( - // "public", - // p.Type.ToDisplayString(), - // p.Name, - // p.GetMethod != null, - // p.SetMethod != null, - // p.IsIndexer - // ? Join( - // ", ", - // p.Parameters.Select( - // p => - // $"{p.Type.ToDisplayString()} {p.Name}" - // ) - // ) - // : "" - // ) - // ) + p => p.ToDisplayString(Constants.SymbolDisplayFormat) + // PropertyDeclarationTemplate.Render( + // new PropertyDeclarationModel( + // "public", + // p.Type.ToDisplayString(), + // p.Name, + // p.GetMethod != null, + // p.SetMethod != null, + // p.IsIndexer + // ? Join( + // ", ", + // p.Parameters.Select( + // p => + // $"{p.Type.ToDisplayString()} {p.Name}" + // ) + // ) + // : "" + // ) + // ) ) ) + Environment.NewLine diff --git a/InterfaceGenerator/InterfaceGeneratorConstants.cs b/InterfaceGenerator/InterfaceGeneratorConstants.cs index 9ad57a0..19c295e 100644 --- a/InterfaceGenerator/InterfaceGeneratorConstants.cs +++ b/InterfaceGenerator/InterfaceGeneratorConstants.cs @@ -36,16 +36,18 @@ public static class Constants using System; [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)] - internal sealed class {{{GenerateInterfaceAttributeName}}} : Attribute - { - public Type Type { get; } - - public {{{GenerateInterfaceAttributeName}}} (Type type = null) - { - { - Type = type; - } - } + internal sealed class {{{GenerateInterfaceAttributeName +}}} : Attribute +{ + public Type Type { get; } + +public +{ { { GenerateInterfaceAttributeName} } } (Type type = null) + { + { + Type = type; + } +} } """; @@ -63,74 +65,76 @@ internal sealed class {{{GenerateInterfaceAttributeName}}} : Attribute namespace {{ namespace }} { - public partial interface {{ interface_name }} - { - {{ members }} - } + public partial interface {{ interface_name +}} + { + { { members } } +} } """; public static readonly Scriban.Template InterfaceDeclarationTemplate = - Scriban.Template.Parse(InterfaceDeclaration); - - public const string MethodDeclaration = "{{ full_definition }};"; - - public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse( - MethodDeclaration - ); - - public const string MethodParameter = """ - {{ type }} {{ name }} - """; + Scriban.Template.Parse(InterfaceDeclaration); + +public const string MethodDeclaration = "{{ full_definition }};"; + +public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse( + MethodDeclaration +); + +public const string MethodParameter = """ + { { type } } +{ { name } } +"""; public static readonly Scriban.Template MethodParameterTemplate = Scriban.Template.Parse( MethodParameter - ); - - public const string PropertyDeclaration = - "{{ type }} {{ if is_indexed }}this[ {{ indexers }}] {{ else }} {{ name }} {{ end }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} }"; - - public static readonly Scriban.Template PropertyDeclarationTemplate = - Scriban.Template.Parse(PropertyDeclaration); - - public static readonly SymbolDisplayFormat SymbolDisplayFormat = - // new( - // typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - // genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, - // memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeType, - // parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName, - // propertyStyle: SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, - // miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - // /* - new( - SymbolDisplayGlobalNamespaceStyle.Included, - SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - SymbolDisplayGenericsOptions.IncludeTypeParameters - | SymbolDisplayGenericsOptions.IncludeVariance - | SymbolDisplayGenericsOptions.IncludeTypeConstraints, - SymbolDisplayMemberOptions.IncludeExplicitInterface - | SymbolDisplayMemberOptions.IncludeModifiers - | SymbolDisplayMemberOptions.IncludeParameters - | SymbolDisplayMemberOptions.IncludeRef - | SymbolDisplayMemberOptions.IncludeType - // | SymbolDisplayMemberOptions.IncludeContainingType - | SymbolDisplayMemberOptions.IncludeAccessibility, - SymbolDisplayDelegateStyle.NameAndSignature, - SymbolDisplayExtensionMethodStyle.Default, - SymbolDisplayParameterOptions.IncludeExtensionThis - | SymbolDisplayParameterOptions.IncludeName - | SymbolDisplayParameterOptions.IncludeParamsRefOut - | SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeDefaultValue - | SymbolDisplayParameterOptions.IncludeOptionalBrackets, - SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers - | SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays - | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier - | SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier - ); + ); + +public const string PropertyDeclaration = + "{{ type }} {{ if is_indexed }}this[ {{ indexers }}] {{ else }} {{ name }} {{ end }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} }"; + +public static readonly Scriban.Template PropertyDeclarationTemplate = + Scriban.Template.Parse(PropertyDeclaration); + +public static readonly SymbolDisplayFormat SymbolDisplayFormat = + // new( + // typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + // genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + // memberOptions: SymbolDisplayMemberOptions.IncludeParameters | SymbolDisplayMemberOptions.IncludeType, + // parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeName, + // propertyStyle: SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, + // miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes + // /* + new( + SymbolDisplayGlobalNamespaceStyle.Included, + SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + SymbolDisplayGenericsOptions.IncludeTypeParameters + | SymbolDisplayGenericsOptions.IncludeVariance + | SymbolDisplayGenericsOptions.IncludeTypeConstraints, + SymbolDisplayMemberOptions.IncludeExplicitInterface + | SymbolDisplayMemberOptions.IncludeModifiers + | SymbolDisplayMemberOptions.IncludeParameters + | SymbolDisplayMemberOptions.IncludeRef + | SymbolDisplayMemberOptions.IncludeType + // | SymbolDisplayMemberOptions.IncludeContainingType + | SymbolDisplayMemberOptions.IncludeAccessibility, + SymbolDisplayDelegateStyle.NameAndSignature, + SymbolDisplayExtensionMethodStyle.Default, + SymbolDisplayParameterOptions.IncludeExtensionThis + | SymbolDisplayParameterOptions.IncludeName + | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeType + | SymbolDisplayParameterOptions.IncludeDefaultValue + | SymbolDisplayParameterOptions.IncludeOptionalBrackets, + SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes + | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + | SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays + | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier + ); } public record struct InterfaceGeneratorModel( @@ -139,10 +143,10 @@ public record struct InterfaceGeneratorModel( string Members, string TypeParameters, string TypeConstraints - ); - - public static class Environment - { - public const string NewLine = "\r\n"; - } + ); + +public static class Environment +{ + public const string NewLine = "\r\n"; +} }