-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Extensions: add Name property on embedded ExtensionMarkerAttribute #80456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b62e77a to
7e16850
Compare
| } | ||
|
|
||
| public override IEnumerable<string> MemberNames | ||
| => [_nameField.Name, PropertyName, WellKnownMemberNames.InstanceConstructorName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using only constants:
| => [_nameField.Name, PropertyName, WellKnownMemberNames.InstanceConstructorName]; | |
| => [FieldName, PropertyName, WellKnownMemberNames.InstanceConstructorName]; | |
| ``` #Resolved |
| public override MethodSymbol GetMethod { get; } | ||
| public override MethodSymbol? SetMethod => null; | ||
| public override Symbol ContainingSymbol => _backingField.ContainingSymbol; | ||
| public override Accessibility DeclaredAccessibility => Accessibility.Internal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be public to match the runtime API? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The embedded type is internal (see SynthesizedEmbeddedAttributeSymbolBase.DeclaredAccessibility), so public or internal here are equivalent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should match the accesibility
| public override ImmutableArray<ParameterSymbol> Parameters => []; | ||
| public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations => []; | ||
| public override ImmutableArray<Location> Locations => []; | ||
| public override Accessibility DeclaredAccessibility => Accessibility.Internal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have the same accessibility as the property?
| public override Accessibility DeclaredAccessibility => Accessibility.Internal; | |
| public override Accessibility DeclaredAccessibility => AssociatedSymbol.DeclaredAccessibility; | |
| ``` #Resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the same and we already know the value, so doesn't seem useful to delegate
| m => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, TypeWithAnnotations.Create(systemStringType), 0, RefKind.None, name: "name")))); | ||
| Debug.Assert(FieldName == GeneratedNames.MakeBackingFieldName(PropertyName)); | ||
|
|
||
| _nameField = new SynthesizedFieldSymbol(this, systemStringType, FieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private sealed class ConstructorSymbol : SynthesizedInstanceConstructor | ||
| { | ||
| private readonly ImmutableArray<ParameterSymbol> _parameters; | ||
| private readonly SynthesizedFieldSymbol _nameField; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| SynthesizedFieldSymbol nameField) : | ||
| base(containingType) | ||
| { | ||
| _parameters = [SynthesizedParameterSymbol.Create(containingType, TypeWithAnnotations.Create(systemStringType), ordinal: 0, RefKind.None, name: "name")]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public override IEnumerable<string> MemberNames | ||
| => [FieldName, PropertyName, WellKnownMemberNames.InstanceConstructorName]; | ||
|
|
||
| private sealed class ConstructorSymbol : SynthesizedInstanceConstructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private sealed partial class NameGetAccessorMethodSymbol : SynthesizedMethodSymbol | ||
| { | ||
| private readonly NamePropertySymbol _nameProperty; | ||
| private readonly SynthesizedFieldSymbol _backingField; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics) | ||
| { | ||
| SyntheticBoundNodeFactory F = new SyntheticBoundNodeFactory(this, this.GetNonNullSyntaxNode(), compilationState, diagnostics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public override ImmutableArray<ParameterSymbol> Parameters => []; | ||
| public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations => []; | ||
| public override ImmutableArray<Location> Locations => []; | ||
| public override Accessibility DeclaredAccessibility => Accessibility.Internal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Forget it, it's fine
| } | ||
| catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex) | ||
| { | ||
| diagnostics.Add(ex.Diagnostic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| IL_000d: ret | ||
| } // end of method ExtensionMarkerAttribute::.ctor | ||
| // Properties | ||
| .property instance string Name() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a test below does that.
| { | ||
| FieldName => [_nameField], | ||
| PropertyName => [_nameProperty], | ||
| WellKnownMemberNames.InstanceConstructorName => [_constructors[0]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types don't line up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types don't line up
There is a CastUp helper that allows to cast to an array of base class without reallocation
|
Done with review pass (commit 2) #Closed |
| try | ||
| { | ||
| // return this._backingField; | ||
| F.CloseMethod(F.Return(F.Field(F.This(), ((SynthesizedEmbeddedExtensionMarkerAttributeSymbol)_nameProperty.ContainingSymbol)._nameField))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Fields | ||
| .field private initonly string '<Name>k__BackingField' | ||
| // Methods | ||
| .method assembly hidebysig specialname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Done with review pass (commit 3) #Closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 5)
Addresses part of #78963 ("Add Name property to synthesized attribute")
This shape matches that of the BCL attribute: dotnet/runtime#118179
Relates to test plan #76130