Skip to content

Commit f36d913

Browse files
authored
Merge pull request #93 from LilithSilver/t4-genericattributes
Remove Attributes.g.cs source generation in favor of T4 templates
2 parents 43251aa + c63efb4 commit f36d913

7 files changed

Lines changed: 813 additions & 62 deletions

File tree

Arch.System.SourceGenerator/GenericAttributes.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

Arch.System.SourceGenerator/SourceGenerator.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
1717
{
1818
//if (!Debugger.IsAttached) Debugger.Launch();
1919

20-
// Register the generic attributes
21-
var attributes = $$"""
22-
namespace Arch.System.SourceGenerator
23-
{
24-
#if NET7_0_OR_GREATER
25-
{{new StringBuilder().AppendGenericAttributes("All", "All", 25)}}
26-
{{new StringBuilder().AppendGenericAttributes("Any", "Any", 25)}}
27-
{{new StringBuilder().AppendGenericAttributes("None", "None", 25)}}
28-
{{new StringBuilder().AppendGenericAttributes("Exclusive", "Exclusive", 25)}}
29-
#endif
30-
}
31-
""";
32-
context.RegisterPostInitializationOutput(ctx => ctx.AddSource("Attributes.g.cs", SourceText.From(attributes, Encoding.UTF8)));
33-
3420
// Do a simple filter for methods marked with update
3521
IncrementalValuesProvider<MethodDeclarationSyntax> methodDeclarations = context.SyntaxProvider.CreateSyntaxProvider(
3622
static (s, _) => s is MethodDeclarationSyntax { AttributeLists.Count: > 0 },

Arch.System/Arch.System.csproj

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net7.0; net6.0; netstandard2.1</TargetFrameworks>
@@ -32,4 +32,22 @@
3232
<UnityPublish>true</UnityPublish>
3333
</PropertyGroup>
3434

35+
<ItemGroup>
36+
<None Update="Templates\GenericAttributes.tt">
37+
<Generator>TextTemplatingFileGenerator</Generator>
38+
<LastGenOutput>GenericAttributes.cs</LastGenOutput>
39+
</None>
40+
</ItemGroup>
41+
42+
<ItemGroup>
43+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
44+
</ItemGroup>
45+
46+
<ItemGroup>
47+
<Compile Update="Templates\GenericAttributes.cs">
48+
<DesignTime>True</DesignTime>
49+
<AutoGen>True</AutoGen>
50+
<DependentUpon>GenericAttributes.tt</DependentUpon>
51+
</Compile>
52+
</ItemGroup>
3553
</Project>

Arch.System/Attributes.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class AllAttribute : global::System.Attribute
3232
/// </summary>
3333
public Type[] ComponentTypes { get; }
3434

35+
/// <summary>
36+
/// Constructs an All attribute with the specified component types.
37+
/// </summary>
38+
/// <param name="componentTypes">The types of the components that should be present.</param>
3539
public AllAttribute(params Type[] componentTypes)
3640
{
3741
ComponentTypes = componentTypes;
@@ -49,6 +53,10 @@ public class AnyAttribute : global::System.Attribute
4953
/// </summary>
5054
public Type[] ComponentTypes { get; }
5155

56+
/// <summary>
57+
/// Constructs an Any attribute with the specified component types.
58+
/// </summary>
59+
/// <param name="componentTypes">The types of the components that can be present.</param>
5260
public AnyAttribute(params Type[] componentTypes)
5361
{
5462
ComponentTypes = componentTypes;
@@ -67,6 +75,10 @@ public class NoneAttribute : global::System.Attribute
6775
/// </summary>
6876
public Type[] ComponentTypes { get; }
6977

78+
/// <summary>
79+
/// Constructs a None attribute with the specified component types.
80+
/// </summary>
81+
/// <param name="componentTypes">The types of the components that should not be present.</param>
7082
public NoneAttribute(params Type[] componentTypes)
7183
{
7284
ComponentTypes = componentTypes;
@@ -79,12 +91,15 @@ public NoneAttribute(params Type[] componentTypes)
7991
[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = true)]
8092
public class ExclusiveAttribute : global::System.Attribute
8193
{
82-
8394
/// <summary>
8495
/// The types of the component.
8596
/// </summary>
8697
public Type[] ComponentTypes { get; }
8798

99+
/// <summary>
100+
/// Constructs an exclusive attribute with the specified component types.
101+
/// </summary>
102+
/// <param name="componentTypes">The types of the components that should be present exclusively.</param>
88103
public ExclusiveAttribute(params Type[] componentTypes)
89104
{
90105
ComponentTypes = componentTypes;

0 commit comments

Comments
 (0)