Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions src/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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);

Expand Down
7 changes: 4 additions & 3 deletions src/InterfaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() : ""))}
" : "")))))));
}
}
}


Expand Down