feat: Source generator for Cloud Events#75
Open
tsutomi wants to merge 12 commits into
Open
Conversation
Comment on lines
+119
to
+127
| else if (eventJsonSerializationOptionsAttribute is not null && SymbolEqualityComparer.Default.Equals(attrClass, eventJsonSerializationOptionsAttribute)) | ||
| { | ||
| // Constructor arg 0: providerType | ||
| if (attr.ConstructorArguments.Length >= 1 && | ||
| attr.ConstructorArguments[0].Value is INamedTypeSymbol t) | ||
| { | ||
| jsonOptionsProviderTypeName = t.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); | ||
| } | ||
| } |
Comment on lines
+96
to
+99
| catch | ||
| { | ||
| // ignore unresolvable references (e.g. native shims) | ||
| } |
Comment on lines
+78
to
+83
| foreach (var t in assemblyTypes) | ||
| { | ||
| var loc = t.Assembly.Location; | ||
| if (!string.IsNullOrEmpty(loc)) | ||
| refs.Add(MetadataReference.CreateFromFile(loc)); | ||
| } |
Comment on lines
+155
to
+162
| foreach (var m in decl.Modifiers) | ||
| { | ||
| if (m.IsKind(SyntaxKind.PartialKeyword)) | ||
| { | ||
| isPartial = true; | ||
| break; | ||
| } | ||
| } |
Comment on lines
+172
to
+179
| foreach (var a in ctx.Attributes) | ||
| { | ||
| if (a.AttributeClass?.ToDisplayString() == EventAttributeFullName) | ||
| { | ||
| eventAttr = a; | ||
| break; | ||
| } | ||
| } |
Comment on lines
+223
to
+256
| foreach (var attrData in symbol.GetAttributes()) | ||
| { | ||
| if (attrData.AttributeClass?.ToDisplayString() != EventAttributesAttributeFullName) | ||
| continue; | ||
| if (attrData.ConstructorArguments.Length < 2) | ||
| continue; | ||
|
|
||
| var attrName = attrData.ConstructorArguments[0].Value as string; | ||
| if (attrName is null) | ||
| continue; | ||
|
|
||
| if (IsEventMetadataReservedName(attrName)) | ||
| { | ||
| collidingNames.Add(attrName); | ||
| continue; | ||
| } | ||
|
|
||
| if (!IsStandardCloudEventAttribute(attrName) && !IsValidCloudEventExtensionName(attrName)) | ||
| { | ||
| invalidExtensionNames.Add(attrName); | ||
| continue; | ||
| } | ||
|
|
||
| var valueConst = attrData.ConstructorArguments[1]; | ||
| var (valueExpression, attributeType) = GetAttributeValueInfo(valueConst); | ||
|
|
||
| extraAttributes.Add(new EventAttributeData | ||
| { | ||
| Name = attrName, | ||
| ValueExpression = valueExpression, | ||
| CloudEventAttributeType = attributeType, | ||
| IsStandardAttribute = IsStandardCloudEventAttribute(attrName) | ||
| }); | ||
| } |
Comment on lines
+479
to
+481
| foreach (var s in StandardCloudEventAttributeNames) | ||
| if (string.Equals(s, name, StringComparison.OrdinalIgnoreCase)) | ||
| return true; |
Comment on lines
+487
to
+489
| foreach (var s in EventMetadataReservedNames) | ||
| if (string.Equals(s, name, StringComparison.OrdinalIgnoreCase)) | ||
| return true; |
Comment on lines
+498
to
+502
| foreach (char c in name) | ||
| { | ||
| if ((c < 'a' || c > 'z') && (c < '0' || c > '9')) | ||
| return false; | ||
| } |
# Conflicts: # .gitignore # Deveel.Events.sln # docs/concepts/event-annotations.md # docs/samples/README.md # samples/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request primarily adds a new sample demonstrating the use of source generators for event publishing with MassTransit, and improves documentation and build tooling for samples. It also updates the ASP.NET publisher sample to use binary references and provides dedicated build scripts for its dependencies.
New sample: Event generation with MassTransit
event-genration) that demonstrates source-generatedIEventConvertibleevent classes using[Event]annotations and publishing via MassTransit, including documentation and a walkthrough of assembly-level generator attributes. [1] [2] [3] [4]Documentation improvements
[EventDataSchemaUri],[EventJsonSerializationOptions]) affect source-generated event code, including schema URI and JSON serialization resolution. [1] [2]Sample build tooling
build-libs.sh,.ps1,.bat) for the ASP.NET publisher sample, which delegate to shared core scripts to build and copy required binaries into alibsfolder. [1] [2] [3]libsfolder instead of using project references.Solution/project structure
This pull request introduces a new sample demonstrating source-generated event publishing with MassTransit, updates documentation to explain new generator features, and improves the build/dependency management for samples. It also adds two new projects to the solution for the event generator and its tests, and refines how dependencies are referenced in the ASP.NET publisher sample.
New sample and documentation:
Added a new sample,
event-genration, showing how to use[Event]source generation with MassTransit, including assembly-level generator attributes for schema URI and JSON serialization options. Documentation for this sample is included and linked from relevant indexes. [1] [2] [3] [4]Expanded documentation to explain the new assembly-level generator attributes (
EventDataSchemaUriandEventJsonSerializationOptions) and how the generator resolves schema URIs and JSON options at compile-time or runtime. [1] [2]Solution and build system updates:
Added
Deveel.Events.Generatorsand its XUnit test project to the solution file, with appropriate build configurations and solution folder assignments. [1] [2] [3]Added shared build scripts for samples to centralize dependency compilation and copying, and introduced per-sample scripts that delegate to these core scripts. [1] [2] [3] [4]
Sample dependency management:
OrderService.SimplePublishersample to reference Deveel.Events dependencies as binaries from a locallibsfolder, rather than as project references, and documented this workflow. [1] [2]These changes collectively make it easier to use and understand the new source generator features, improve sample isolation and reproducibility, and streamline the build process for contributors.
References: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]