com.wallstop-studios.dxmessaging 2.0.0-rc12 → 2.0.0-rc13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/.gitattributes +63 -63
  2. package/.github/workflows/npm-publish.yml +66 -0
  3. package/CHANGELOG.md.meta +7 -7
  4. package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +33 -33
  5. package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +33 -33
  6. package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +33 -33
  7. package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +71 -71
  8. package/Editor/Analyzers.meta +8 -8
  9. package/Editor/SetupCscRsp.cs +162 -162
  10. package/Editor/SetupCscRsp.cs.meta +2 -2
  11. package/Editor/WallstopStudios.DxMessaging.Editor.asmdef +17 -17
  12. package/Editor/WallstopStudios.DxMessaging.Editor.asmdef.meta +7 -7
  13. package/Editor.meta +8 -8
  14. package/LICENSE.md +6 -6
  15. package/LICENSE.md.meta +7 -7
  16. package/README.md +387 -364
  17. package/README.md.meta +7 -7
  18. package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs +7 -7
  19. package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs.meta +2 -2
  20. package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +7 -7
  21. package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +2 -2
  22. package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +7 -7
  23. package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +2 -2
  24. package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +7 -7
  25. package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +2 -2
  26. package/Runtime/Core/Attributes.meta +2 -2
  27. package/Runtime/Core/Extensions/MessageExtensions.cs +342 -342
  28. package/Runtime/Core/Extensions/MessageExtensions.cs.meta +11 -11
  29. package/Runtime/Core/Extensions.meta +8 -8
  30. package/Runtime/Core/IMessage.cs +12 -12
  31. package/Runtime/Core/IMessage.cs.meta +11 -11
  32. package/Runtime/Core/InstanceId.cs +149 -149
  33. package/Runtime/Core/InstanceId.cs.meta +11 -11
  34. package/Runtime/Core/MessageBus/IMessageBus.cs +309 -309
  35. package/Runtime/Core/MessageBus/IMessageBus.cs.meta +11 -11
  36. package/Runtime/Core/MessageBus/MessageBus.cs +2243 -2084
  37. package/Runtime/Core/MessageBus/MessageBus.cs.meta +11 -11
  38. package/Runtime/Core/MessageBus/MessagingRegistration.cs +105 -105
  39. package/Runtime/Core/MessageBus/MessagingRegistration.cs.meta +11 -11
  40. package/Runtime/Core/MessageBus/RegistrationLog.cs +111 -111
  41. package/Runtime/Core/MessageBus/RegistrationLog.cs.meta +11 -11
  42. package/Runtime/Core/MessageBus.meta +8 -8
  43. package/Runtime/Core/MessageHandler.cs +2778 -2759
  44. package/Runtime/Core/MessageHandler.cs.meta +11 -11
  45. package/Runtime/Core/MessageRegistrationHandle.cs +110 -110
  46. package/Runtime/Core/MessageRegistrationHandle.cs.meta +11 -11
  47. package/Runtime/Core/MessageRegistrationToken.cs +1234 -1234
  48. package/Runtime/Core/MessageRegistrationToken.cs.meta +11 -11
  49. package/Runtime/Core/Messages/IBroadcastMessage.cs +27 -27
  50. package/Runtime/Core/Messages/IBroadcastMessage.cs.meta +11 -11
  51. package/Runtime/Core/Messages/ITargetedMessage.cs +27 -27
  52. package/Runtime/Core/Messages/ITargetedMessage.cs.meta +11 -11
  53. package/Runtime/Core/Messages/IUntargetedMessage.cs +27 -27
  54. package/Runtime/Core/Messages/IUntargetedMessage.cs.meta +11 -11
  55. package/Runtime/Core/Messages.meta +8 -8
  56. package/Runtime/Core/MessagingDebug.cs +70 -70
  57. package/Runtime/Core/MessagingDebug.cs.meta +11 -11
  58. package/Runtime/Core.meta +8 -8
  59. package/Runtime/Unity/MessageAwareComponent.cs +77 -77
  60. package/Runtime/Unity/MessageAwareComponent.cs.meta +11 -11
  61. package/Runtime/Unity/MessagingComponent.cs +99 -99
  62. package/Runtime/Unity/MessagingComponent.cs.meta +11 -11
  63. package/Runtime/Unity.meta +8 -8
  64. package/Runtime/WallstopStudios.DxMessaging.asmdef +15 -15
  65. package/Runtime.meta +8 -8
  66. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs +92 -92
  67. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs.meta +11 -11
  68. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs +94 -94
  69. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs.meta +2 -2
  70. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs +94 -94
  71. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs.meta +2 -2
  72. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs +94 -94
  73. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs.meta +2 -2
  74. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +21 -21
  75. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj.meta +7 -7
  76. package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.meta +8 -8
  77. package/SourceGenerators.meta +8 -8
  78. package/Tests/Runtime/Benchmarks/PerformanceTests.cs +373 -310
  79. package/Tests/Runtime/Benchmarks/PerformanceTests.cs.meta +11 -11
  80. package/Tests/Runtime/Benchmarks.meta +8 -8
  81. package/Tests/Runtime/Core/BroadcastTests.cs +899 -899
  82. package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +190 -190
  83. package/Tests/Runtime/Core/GlobalAcceptAllTests.cs.meta +11 -11
  84. package/Tests/Runtime/Core/MessagingTestBase.cs +185 -185
  85. package/Tests/Runtime/Core/MessagingTestBase.cs.meta +11 -11
  86. package/Tests/Runtime/Core/NominalTests.cs +1740 -1740
  87. package/Tests/Runtime/Core/PostProcessorTests.cs +1236 -1236
  88. package/Tests/Runtime/Core/PostProcessorTests.cs.meta +11 -11
  89. package/Tests/Runtime/Core/RegistrationTests.cs +1266 -1266
  90. package/Tests/Runtime/Core/RegistrationTests.cs.meta +11 -11
  91. package/Tests/Runtime/Core/TargetedTests.cs +888 -888
  92. package/Tests/Runtime/Core/TargetedTests.cs.meta +11 -11
  93. package/Tests/Runtime/Core/UntargetedTests.cs +272 -272
  94. package/Tests/Runtime/Core/UntargetedTests.cs.meta +11 -11
  95. package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +9 -9
  96. package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs.meta +11 -11
  97. package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +186 -186
  98. package/Tests/Runtime/Scripts/Messages/ComplexTargetedMessage.cs +30 -30
  99. package/Tests/Runtime/Scripts/Messages/SimpleBroadcastMessage.cs +8 -8
  100. package/Tests/Runtime/Scripts/Messages/SimpleTargetedMessage.cs +8 -8
  101. package/Tests/Runtime/Scripts/Messages/SimpleUntargetedMessage.cs +8 -8
  102. package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +7 -7
  103. package/Tests.meta +8 -8
  104. package/Third Party Notices.md.meta +7 -7
  105. package/package.json +36 -36
  106. package/package.json.meta +7 -7
@@ -1,94 +1,94 @@
1
- namespace WallstopStudios.DxMessaging.SourceGenerators;
2
-
3
- using System.Collections.Generic;
4
- using System.Linq;
5
- using System.Text;
6
- using Microsoft.CodeAnalysis;
7
- using Microsoft.CodeAnalysis.CSharp;
8
- using Microsoft.CodeAnalysis.CSharp.Syntax;
9
- using Microsoft.CodeAnalysis.Text;
10
-
11
- [Generator]
12
- public sealed class DxBroadcastMessageGenerator : ISourceGenerator
13
- {
14
- public void Initialize(GeneratorInitializationContext context)
15
- {
16
- context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
17
- }
18
-
19
- public void Execute(GeneratorExecutionContext context)
20
- {
21
- if (context.SyntaxReceiver is not SyntaxReceiver receiver)
22
- {
23
- return;
24
- }
25
-
26
- INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
27
- "DxMessaging.Core.Attributes.DxBroadcastMessageAttribute"
28
- );
29
-
30
- foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
31
- {
32
- SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
33
- ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
34
-
35
- if (
36
- classSymbol
37
- .GetAttributes()
38
- .Any(attributeData =>
39
- attributeData.AttributeClass.Equals(
40
- attributeSymbol,
41
- SymbolEqualityComparer.Default
42
- )
43
- )
44
- )
45
- {
46
- string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
47
- string className = classSymbol.Name;
48
- string typeKind =
49
- classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
50
-
51
- string source = $$"""
52
-
53
- namespace {{namespaceName}}
54
- {
55
- using DxMessaging.Core.Messages;
56
-
57
- public partial {{typeKind}} {{className}} : IBroadcastMessage
58
- {
59
- public System.Type MessageType => typeof({{className}});
60
- }
61
- }
62
-
63
- """;
64
-
65
- context.AddSource(
66
- $"{className}_DxBroadcastMessage.g.cs",
67
- SourceText.From(source, Encoding.UTF8)
68
- );
69
- }
70
- }
71
- }
72
-
73
- private sealed class SyntaxReceiver : ISyntaxReceiver
74
- {
75
- public List<TypeDeclarationSyntax> CandidateClasses { get; } = [];
76
-
77
- public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
78
- {
79
- if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
80
- {
81
- if (
82
- typeDeclarationSyntax.AttributeLists.Count > 0
83
- && (
84
- typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
85
- || typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
86
- )
87
- )
88
- {
89
- CandidateClasses.Add(typeDeclarationSyntax);
90
- }
91
- }
92
- }
93
- }
94
- }
1
+ namespace WallstopStudios.DxMessaging.SourceGenerators;
2
+
3
+ using System.Collections.Generic;
4
+ using System.Linq;
5
+ using System.Text;
6
+ using Microsoft.CodeAnalysis;
7
+ using Microsoft.CodeAnalysis.CSharp;
8
+ using Microsoft.CodeAnalysis.CSharp.Syntax;
9
+ using Microsoft.CodeAnalysis.Text;
10
+
11
+ [Generator]
12
+ public sealed class DxBroadcastMessageGenerator : ISourceGenerator
13
+ {
14
+ public void Initialize(GeneratorInitializationContext context)
15
+ {
16
+ context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
17
+ }
18
+
19
+ public void Execute(GeneratorExecutionContext context)
20
+ {
21
+ if (context.SyntaxReceiver is not SyntaxReceiver receiver)
22
+ {
23
+ return;
24
+ }
25
+
26
+ INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
27
+ "DxMessaging.Core.Attributes.DxBroadcastMessageAttribute"
28
+ );
29
+
30
+ foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
31
+ {
32
+ SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
33
+ ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
34
+
35
+ if (
36
+ classSymbol
37
+ .GetAttributes()
38
+ .Any(attributeData =>
39
+ attributeData.AttributeClass.Equals(
40
+ attributeSymbol,
41
+ SymbolEqualityComparer.Default
42
+ )
43
+ )
44
+ )
45
+ {
46
+ string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
47
+ string className = classSymbol.Name;
48
+ string typeKind =
49
+ classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
50
+
51
+ string source = $$"""
52
+
53
+ namespace {{namespaceName}}
54
+ {
55
+ using DxMessaging.Core.Messages;
56
+
57
+ public partial {{typeKind}} {{className}} : IBroadcastMessage
58
+ {
59
+ public System.Type MessageType => typeof({{className}});
60
+ }
61
+ }
62
+
63
+ """;
64
+
65
+ context.AddSource(
66
+ $"{className}_DxBroadcastMessage.g.cs",
67
+ SourceText.From(source, Encoding.UTF8)
68
+ );
69
+ }
70
+ }
71
+ }
72
+
73
+ private sealed class SyntaxReceiver : ISyntaxReceiver
74
+ {
75
+ public List<TypeDeclarationSyntax> CandidateClasses { get; } = [];
76
+
77
+ public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
78
+ {
79
+ if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
80
+ {
81
+ if (
82
+ typeDeclarationSyntax.AttributeLists.Count > 0
83
+ && (
84
+ typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
85
+ || typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
86
+ )
87
+ )
88
+ {
89
+ CandidateClasses.Add(typeDeclarationSyntax);
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
@@ -1,3 +1,3 @@
1
- fileFormatVersion: 2
2
- guid: 9f20e167b1f4496cae198016fa738fe1
1
+ fileFormatVersion: 2
2
+ guid: 9f20e167b1f4496cae198016fa738fe1
3
3
  timeCreated: 1730836618
@@ -1,94 +1,94 @@
1
- namespace WallstopStudios.DxMessaging.SourceGenerators;
2
-
3
- using System.Collections.Generic;
4
- using System.Linq;
5
- using System.Text;
6
- using Microsoft.CodeAnalysis;
7
- using Microsoft.CodeAnalysis.CSharp;
8
- using Microsoft.CodeAnalysis.CSharp.Syntax;
9
- using Microsoft.CodeAnalysis.Text;
10
-
11
- [Generator]
12
- public sealed class DxTargetedMessageGenerator : ISourceGenerator
13
- {
14
- public void Initialize(GeneratorInitializationContext context)
15
- {
16
- context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
17
- }
18
-
19
- public void Execute(GeneratorExecutionContext context)
20
- {
21
- if (context.SyntaxReceiver is not SyntaxReceiver receiver)
22
- {
23
- return;
24
- }
25
-
26
- INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
27
- "DxMessaging.Core.Attributes.DxTargetedMessageAttribute"
28
- );
29
-
30
- foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
31
- {
32
- SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
33
- ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
34
-
35
- if (
36
- classSymbol
37
- .GetAttributes()
38
- .Any(attributeData =>
39
- attributeData.AttributeClass.Equals(
40
- attributeSymbol,
41
- SymbolEqualityComparer.Default
42
- )
43
- )
44
- )
45
- {
46
- string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
47
- string className = classSymbol.Name;
48
- string typeKind =
49
- classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
50
-
51
- string source = $$"""
52
-
53
- namespace {{namespaceName}}
54
- {
55
- using DxMessaging.Core.Messages;
56
-
57
- public partial {{typeKind}} {{className}} : ITargetedMessage
58
- {
59
- public System.Type MessageType => typeof({{className}});
60
- }
61
- }
62
-
63
- """;
64
-
65
- context.AddSource(
66
- $"{className}_DxTargetedMessage.g.cs",
67
- SourceText.From(source, Encoding.UTF8)
68
- );
69
- }
70
- }
71
- }
72
-
73
- private sealed class SyntaxReceiver : ISyntaxReceiver
74
- {
75
- public List<TypeDeclarationSyntax> CandidateClasses { get; } = [];
76
-
77
- public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
78
- {
79
- if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
80
- {
81
- if (
82
- typeDeclarationSyntax.AttributeLists.Count > 0
83
- && (
84
- typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
85
- || typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
86
- )
87
- )
88
- {
89
- CandidateClasses.Add(typeDeclarationSyntax);
90
- }
91
- }
92
- }
93
- }
94
- }
1
+ namespace WallstopStudios.DxMessaging.SourceGenerators;
2
+
3
+ using System.Collections.Generic;
4
+ using System.Linq;
5
+ using System.Text;
6
+ using Microsoft.CodeAnalysis;
7
+ using Microsoft.CodeAnalysis.CSharp;
8
+ using Microsoft.CodeAnalysis.CSharp.Syntax;
9
+ using Microsoft.CodeAnalysis.Text;
10
+
11
+ [Generator]
12
+ public sealed class DxTargetedMessageGenerator : ISourceGenerator
13
+ {
14
+ public void Initialize(GeneratorInitializationContext context)
15
+ {
16
+ context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
17
+ }
18
+
19
+ public void Execute(GeneratorExecutionContext context)
20
+ {
21
+ if (context.SyntaxReceiver is not SyntaxReceiver receiver)
22
+ {
23
+ return;
24
+ }
25
+
26
+ INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
27
+ "DxMessaging.Core.Attributes.DxTargetedMessageAttribute"
28
+ );
29
+
30
+ foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
31
+ {
32
+ SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
33
+ ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
34
+
35
+ if (
36
+ classSymbol
37
+ .GetAttributes()
38
+ .Any(attributeData =>
39
+ attributeData.AttributeClass.Equals(
40
+ attributeSymbol,
41
+ SymbolEqualityComparer.Default
42
+ )
43
+ )
44
+ )
45
+ {
46
+ string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
47
+ string className = classSymbol.Name;
48
+ string typeKind =
49
+ classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
50
+
51
+ string source = $$"""
52
+
53
+ namespace {{namespaceName}}
54
+ {
55
+ using DxMessaging.Core.Messages;
56
+
57
+ public partial {{typeKind}} {{className}} : ITargetedMessage
58
+ {
59
+ public System.Type MessageType => typeof({{className}});
60
+ }
61
+ }
62
+
63
+ """;
64
+
65
+ context.AddSource(
66
+ $"{className}_DxTargetedMessage.g.cs",
67
+ SourceText.From(source, Encoding.UTF8)
68
+ );
69
+ }
70
+ }
71
+ }
72
+
73
+ private sealed class SyntaxReceiver : ISyntaxReceiver
74
+ {
75
+ public List<TypeDeclarationSyntax> CandidateClasses { get; } = [];
76
+
77
+ public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
78
+ {
79
+ if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
80
+ {
81
+ if (
82
+ typeDeclarationSyntax.AttributeLists.Count > 0
83
+ && (
84
+ typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
85
+ || typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
86
+ )
87
+ )
88
+ {
89
+ CandidateClasses.Add(typeDeclarationSyntax);
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
@@ -1,3 +1,3 @@
1
- fileFormatVersion: 2
2
- guid: d2d62958607d4a9284c0151e3ab03806
1
+ fileFormatVersion: 2
2
+ guid: d2d62958607d4a9284c0151e3ab03806
3
3
  timeCreated: 1730836745
@@ -1,94 +1,94 @@
1
- namespace WallstopStudios.DxMessaging.SourceGenerators;
2
-
3
- using System.Collections.Generic;
4
- using System.Linq;
5
- using System.Text;
6
- using Microsoft.CodeAnalysis;
7
- using Microsoft.CodeAnalysis.CSharp;
8
- using Microsoft.CodeAnalysis.CSharp.Syntax;
9
- using Microsoft.CodeAnalysis.Text;
10
-
11
- [Generator]
12
- public sealed class DxUntargetedMessageGenerator : ISourceGenerator
13
- {
14
- public void Initialize(GeneratorInitializationContext context)
15
- {
16
- context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
17
- }
18
-
19
- public void Execute(GeneratorExecutionContext context)
20
- {
21
- if (context.SyntaxReceiver is not SyntaxReceiver receiver)
22
- {
23
- return;
24
- }
25
-
26
- INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
27
- "DxMessaging.Core.Attributes.DxUntargetedMessageAttribute"
28
- );
29
-
30
- foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
31
- {
32
- SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
33
- ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
34
-
35
- if (
36
- classSymbol
37
- .GetAttributes()
38
- .Any(attributeData =>
39
- attributeData.AttributeClass.Equals(
40
- attributeSymbol,
41
- SymbolEqualityComparer.Default
42
- )
43
- )
44
- )
45
- {
46
- string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
47
- string className = classSymbol.Name;
48
- string typeKind =
49
- classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
50
-
51
- string source = $$"""
52
-
53
- namespace {{namespaceName}}
54
- {
55
- using DxMessaging.Core.Messages;
56
-
57
- public partial {{typeKind}} {{className}} : IUntargetedMessage
58
- {
59
- public System.Type MessageType => typeof({{className}});
60
- }
61
- }
62
-
63
- """;
64
-
65
- context.AddSource(
66
- $"{className}_DxUntargetedMessage.g.cs",
67
- SourceText.From(source, Encoding.UTF8)
68
- );
69
- }
70
- }
71
- }
72
-
73
- private sealed class SyntaxReceiver : ISyntaxReceiver
74
- {
75
- public List<TypeDeclarationSyntax> CandidateClasses { get; } = [];
76
-
77
- public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
78
- {
79
- if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
80
- {
81
- if (
82
- typeDeclarationSyntax.AttributeLists.Count > 0
83
- && (
84
- typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
85
- || typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
86
- )
87
- )
88
- {
89
- CandidateClasses.Add(typeDeclarationSyntax);
90
- }
91
- }
92
- }
93
- }
94
- }
1
+ namespace WallstopStudios.DxMessaging.SourceGenerators;
2
+
3
+ using System.Collections.Generic;
4
+ using System.Linq;
5
+ using System.Text;
6
+ using Microsoft.CodeAnalysis;
7
+ using Microsoft.CodeAnalysis.CSharp;
8
+ using Microsoft.CodeAnalysis.CSharp.Syntax;
9
+ using Microsoft.CodeAnalysis.Text;
10
+
11
+ [Generator]
12
+ public sealed class DxUntargetedMessageGenerator : ISourceGenerator
13
+ {
14
+ public void Initialize(GeneratorInitializationContext context)
15
+ {
16
+ context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
17
+ }
18
+
19
+ public void Execute(GeneratorExecutionContext context)
20
+ {
21
+ if (context.SyntaxReceiver is not SyntaxReceiver receiver)
22
+ {
23
+ return;
24
+ }
25
+
26
+ INamedTypeSymbol attributeSymbol = context.Compilation.GetTypeByMetadataName(
27
+ "DxMessaging.Core.Attributes.DxUntargetedMessageAttribute"
28
+ );
29
+
30
+ foreach (TypeDeclarationSyntax classDeclaration in receiver.CandidateClasses)
31
+ {
32
+ SemanticModel model = context.Compilation.GetSemanticModel(classDeclaration.SyntaxTree);
33
+ ISymbol classSymbol = ModelExtensions.GetDeclaredSymbol(model, classDeclaration);
34
+
35
+ if (
36
+ classSymbol
37
+ .GetAttributes()
38
+ .Any(attributeData =>
39
+ attributeData.AttributeClass.Equals(
40
+ attributeSymbol,
41
+ SymbolEqualityComparer.Default
42
+ )
43
+ )
44
+ )
45
+ {
46
+ string namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
47
+ string className = classSymbol.Name;
48
+ string typeKind =
49
+ classDeclaration.Kind() == SyntaxKind.ClassDeclaration ? "class" : "struct";
50
+
51
+ string source = $$"""
52
+
53
+ namespace {{namespaceName}}
54
+ {
55
+ using DxMessaging.Core.Messages;
56
+
57
+ public partial {{typeKind}} {{className}} : IUntargetedMessage
58
+ {
59
+ public System.Type MessageType => typeof({{className}});
60
+ }
61
+ }
62
+
63
+ """;
64
+
65
+ context.AddSource(
66
+ $"{className}_DxUntargetedMessage.g.cs",
67
+ SourceText.From(source, Encoding.UTF8)
68
+ );
69
+ }
70
+ }
71
+ }
72
+
73
+ private sealed class SyntaxReceiver : ISyntaxReceiver
74
+ {
75
+ public List<TypeDeclarationSyntax> CandidateClasses { get; } = [];
76
+
77
+ public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
78
+ {
79
+ if (syntaxNode is TypeDeclarationSyntax typeDeclarationSyntax)
80
+ {
81
+ if (
82
+ typeDeclarationSyntax.AttributeLists.Count > 0
83
+ && (
84
+ typeDeclarationSyntax.Kind() == SyntaxKind.ClassDeclaration
85
+ || typeDeclarationSyntax.Kind() == SyntaxKind.StructDeclaration
86
+ )
87
+ )
88
+ {
89
+ CandidateClasses.Add(typeDeclarationSyntax);
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
@@ -1,3 +1,3 @@
1
- fileFormatVersion: 2
2
- guid: d0d88616d75247aab6b3a78bc8078418
1
+ fileFormatVersion: 2
2
+ guid: d0d88616d75247aab6b3a78bc8078418
3
3
  timeCreated: 1730836844
@@ -1,21 +1,21 @@
1
- <Project Sdk="Microsoft.NET.Sdk">
2
-
3
- <PropertyGroup>
4
- <TargetFramework>netstandard2.0</TargetFramework>
5
- <LangVersion>latest</LangVersion>
6
- </PropertyGroup>
7
-
8
- <ItemGroup>
9
- <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
10
- <PrivateAssets>all</PrivateAssets>
11
- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12
- </PackageReference>
13
- <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0">
14
- <PrivateAssets>all</PrivateAssets>
15
- </PackageReference>
16
- <PackageReference Include="System.Collections.Immutable" Version="5.0.0">
17
- <PrivateAssets>all</PrivateAssets>
18
- </PackageReference>
19
- </ItemGroup>
20
-
21
- </Project>
1
+ <Project Sdk="Microsoft.NET.Sdk">
2
+
3
+ <PropertyGroup>
4
+ <TargetFramework>netstandard2.0</TargetFramework>
5
+ <LangVersion>latest</LangVersion>
6
+ </PropertyGroup>
7
+
8
+ <ItemGroup>
9
+ <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
10
+ <PrivateAssets>all</PrivateAssets>
11
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12
+ </PackageReference>
13
+ <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.2.0">
14
+ <PrivateAssets>all</PrivateAssets>
15
+ </PackageReference>
16
+ <PackageReference Include="System.Collections.Immutable" Version="5.0.0">
17
+ <PrivateAssets>all</PrivateAssets>
18
+ </PackageReference>
19
+ </ItemGroup>
20
+
21
+ </Project>
@@ -1,7 +1,7 @@
1
- fileFormatVersion: 2
2
- guid: e4915fed9609ee64f9cbdaaf0324b3d0
3
- DefaultImporter:
4
- externalObjects: {}
5
- userData:
6
- assetBundleName:
7
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: e4915fed9609ee64f9cbdaaf0324b3d0
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -1,8 +1,8 @@
1
- fileFormatVersion: 2
2
- guid: c7573be5899a5694398fa600a0bcd7b1
3
- folderAsset: yes
4
- DefaultImporter:
5
- externalObjects: {}
6
- userData:
7
- assetBundleName:
8
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: c7573be5899a5694398fa600a0bcd7b1
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant: