-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,15 +3,23 @@ | |||||||
| // See the LICENSE file in the project root for more information. | ||||||||
|
|
||||||||
| using System; | ||||||||
| using System.Collections.Generic; | ||||||||
| using System.Collections.Immutable; | ||||||||
| using System.Diagnostics; | ||||||||
| using System.Reflection; | ||||||||
| using Microsoft.Cci; | ||||||||
| using Microsoft.CodeAnalysis.PooledObjects; | ||||||||
|
|
||||||||
| namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||||||||
| { | ||||||||
| // Tracked by https://github.com/dotnet/roslyn/issues/78963 : We are not declaring and not initializing the "Name" property yet. | ||||||||
| internal sealed class SynthesizedEmbeddedExtensionMarkerAttributeSymbol : SynthesizedEmbeddedAttributeSymbolBase | ||||||||
| { | ||||||||
| private readonly ImmutableArray<MethodSymbol> _constructors; | ||||||||
| private readonly SynthesizedFieldSymbol _nameField; | ||||||||
| private readonly NamePropertySymbol _nameProperty; | ||||||||
|
|
||||||||
| private const string PropertyName = "Name"; | ||||||||
| private const string FieldName = "<Name>k__BackingField"; | ||||||||
|
|
||||||||
| public SynthesizedEmbeddedExtensionMarkerAttributeSymbol( | ||||||||
| string name, | ||||||||
|
|
@@ -21,10 +29,11 @@ public SynthesizedEmbeddedExtensionMarkerAttributeSymbol( | |||||||
| TypeSymbol systemStringType) | ||||||||
| : base(name, containingNamespace, containingModule, baseType: systemAttributeType) | ||||||||
| { | ||||||||
| _constructors = ImmutableArray.Create<MethodSymbol>( | ||||||||
| new SynthesizedEmbeddedAttributeConstructorSymbol( | ||||||||
| this, | ||||||||
| 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); | ||||||||
| _nameProperty = new NamePropertySymbol(_nameField); | ||||||||
| _constructors = [new ConstructorSymbol(this, systemStringType, _nameField)]; | ||||||||
|
|
||||||||
| // Ensure we never get out of sync with the description | ||||||||
| Debug.Assert(_constructors.Length == AttributeDescription.ExtensionMarkerAttribute.Signatures.Length); | ||||||||
|
|
@@ -39,5 +48,168 @@ internal override AttributeUsageInfo GetAttributeUsageInfo() | |||||||
| AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, | ||||||||
| allowMultiple: false, inherited: false); | ||||||||
| } | ||||||||
|
|
||||||||
| internal override IEnumerable<FieldSymbol> GetFieldsToEmit() | ||||||||
| { | ||||||||
| return [_nameField]; | ||||||||
| } | ||||||||
|
|
||||||||
| public override ImmutableArray<Symbol> GetMembers() | ||||||||
| => [_nameField, _nameProperty, _nameProperty.GetMethod, _constructors[0]]; | ||||||||
|
|
||||||||
| public override ImmutableArray<Symbol> GetMembers(string name) | ||||||||
| { | ||||||||
| return name switch | ||||||||
| { | ||||||||
| FieldName => [_nameField], | ||||||||
| PropertyName => [_nameProperty], | ||||||||
| WellKnownMemberNames.InstanceConstructorName => [_constructors[0]], | ||||||||
|
||||||||
| _ => [] | ||||||||
| }; | ||||||||
| } | ||||||||
|
|
||||||||
| public override IEnumerable<string> MemberNames | ||||||||
| => [_nameField.Name, PropertyName, WellKnownMemberNames.InstanceConstructorName]; | ||||||||
|
||||||||
| => [_nameField.Name, PropertyName, WellKnownMemberNames.InstanceConstructorName]; | |
| => [FieldName, PropertyName, WellKnownMemberNames.InstanceConstructorName]; | |
| ``` #Resolved |
Outdated
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.
Outdated
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.
Outdated
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.
Outdated
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
Outdated
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.
Outdated
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.
Outdated
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
Outdated
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
Uh oh!
There was an error while loading. Please reload this page.
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.
isReadOnly: true? #Closed