diff --git a/src/Constants.cs b/src/Constants.cs index 6b3d989..6e8cf5f 100644 --- a/src/Constants.cs +++ b/src/Constants.cs @@ -35,18 +35,18 @@ public static class Constants """ using System; - [AttributeUsage(AttributeTargets.Interface)] - internal sealed class GenerateInterfaceAttribute : Attribute - { - public Type Type { get; } - - public GenerateInterfaceAttribute (Type type) - { - { - Type = type; - } - } - } + [AttributeUsage(AttributeTargets.Interface)] +internal sealed class GenerateInterfaceAttribute : Attribute +{ + public Type Type { get; } + + public GenerateInterfaceAttribute(Type type) + { + { + Type = type; + } + } +} """; public const string InterfaceDeclaration = @@ -63,33 +63,39 @@ public GenerateInterfaceAttribute (Type type) 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 = - """ - {{ return_type }} {{ method_name }}({{ parameters }}) {{ type_constraints }}; - """; - - 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 }} {{ name }} { {{~ if is_gettable ~}} get; {{~ end ~}} {{~ if is_settable ~}} set; {{~ end ~}} } - """; + public static readonly Scriban.Template InterfaceDeclarationTemplate = Scriban.Template.Parse(InterfaceDeclaration); + +public const string MethodDeclaration = +""" + { { return_type } } +{ { method_name } } ({ { parameters } }) { { type_constraints } }; +"""; + + 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 } } +{ { name } } +{ { { ~ if is_gettable ~} } get; { { ~end ~} } { { ~ if is_settable ~} } set; { { ~end ~} } } +"""; public static readonly Scriban.Template PropertyDeclarationTemplate = Scriban.Template.Parse(PropertyDeclaration); diff --git a/src/InterfaceGenerator.cs b/src/InterfaceGenerator.cs index 226e3f2..66ddaad 100644 --- a/src/InterfaceGenerator.cs +++ b/src/InterfaceGenerator.cs @@ -87,9 +87,10 @@ protected static void Generate(SourceProductionContext context, ImmutableArray<( (tp.HasReferenceTypeConstraint ? "class" : "") + (tp.HasValueTypeConstraint ? "struct" : "") + Join(", ", tp.ConstraintTypes.Select(ct => ct.ToDisplayString())) + - (tp.HasConstructorConstraint ? "new()" : "").Trim() : ""))}" : ""))))))); - } - } + (tp.HasConstructorConstraint ? "new()" : "").Trim() : ""))} + " : ""))))))); + } +} }