90 lines
3.8 KiB
C#
90 lines
3.8 KiB
C#
using System.Collections.Immutable;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal sealed class SynthesizedBackingFieldSymbol : SynthesizedBackingFieldSymbolBase
|
|
{
|
|
private readonly SourcePropertySymbolBase _property;
|
|
|
|
internal override bool HasInitializer { get; }
|
|
|
|
protected override IAttributeTargetSymbol AttributeOwner => _property.AttributesOwner;
|
|
|
|
internal override Location ErrorLocation => _property.Location;
|
|
|
|
protected override SyntaxList<AttributeListSyntax> AttributeDeclarationSyntaxList => _property.AttributeDeclarationSyntaxList;
|
|
|
|
public override Symbol AssociatedSymbol => _property;
|
|
|
|
public override ImmutableArray<Location> Locations => _property.Locations;
|
|
|
|
public override RefKind RefKind => _property.RefKind;
|
|
|
|
public override ImmutableArray<CustomModifier> RefCustomModifiers => _property.RefCustomModifiers;
|
|
|
|
internal override bool HasPointerType => _property.HasPointerType;
|
|
|
|
public override Symbol ContainingSymbol => _property.ContainingSymbol;
|
|
|
|
public override NamedTypeSymbol ContainingType => _property.ContainingType;
|
|
|
|
public SynthesizedBackingFieldSymbol(SourcePropertySymbolBase property, string name, bool isReadOnly, bool isStatic, bool hasInitializer)
|
|
: base(name, isReadOnly, isStatic)
|
|
{
|
|
_property = property;
|
|
HasInitializer = hasInitializer;
|
|
}
|
|
|
|
internal override TypeWithAnnotations GetFieldType(ConsList<FieldSymbol> fieldsBeingBound)
|
|
{
|
|
return _property.TypeWithAnnotations;
|
|
}
|
|
|
|
protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
|
|
{
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
if (arguments.Attribute.IsTargetAttribute(this, AttributeDescription.FixedBufferAttribute))
|
|
{
|
|
((BindingDiagnosticBag)(object)arguments.Diagnostics).Add(ErrorCode.ERR_DoNotUseFixedBufferAttrOnProperty, ((SyntaxNode)arguments.AttributeSyntaxOpt.Name).Location);
|
|
}
|
|
else
|
|
{
|
|
base.DecodeWellKnownAttributeImpl(ref arguments);
|
|
}
|
|
}
|
|
|
|
internal override void PostDecodeWellKnownAttributes(ImmutableArray<CSharpAttributeData> boundAttributes, ImmutableArray<AttributeSyntax> allAttributeSyntaxNodes, BindingDiagnosticBag diagnostics, AttributeLocation symbolPart, WellKnownAttributeData decodedData)
|
|
{
|
|
base.PostDecodeWellKnownAttributes(boundAttributes, allAttributeSyntaxNodes, diagnostics, symbolPart, decodedData);
|
|
if (!allAttributeSyntaxNodes.IsEmpty && _property.IsAutoPropertyWithGetAccessor)
|
|
{
|
|
CheckForFieldTargetedAttribute(diagnostics);
|
|
}
|
|
}
|
|
|
|
private void CheckForFieldTargetedAttribute(BindingDiagnosticBag diagnostics)
|
|
{
|
|
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
|
|
LanguageVersion languageVersion = DeclaringCompilation.LanguageVersion;
|
|
if (languageVersion.AllowAttributesOnBackingFields())
|
|
{
|
|
return;
|
|
}
|
|
Enumerator<AttributeListSyntax> enumerator = AttributeDeclarationSyntaxList.GetEnumerator();
|
|
while (enumerator.MoveNext())
|
|
{
|
|
AttributeListSyntax current = enumerator.Current;
|
|
AttributeTargetSpecifierSyntax? target = current.Target;
|
|
if (target != null && target.GetAttributeLocation() == AttributeLocation.Field)
|
|
{
|
|
diagnostics.Add((DiagnosticInfo?)(object)new CSDiagnosticInfo(ErrorCode.WRN_AttributesOnBackingFieldsNotAvailable, languageVersion.ToDisplayString(), new CSharpRequiredLanguageVersion(MessageID.IDS_FeatureAttributesOnBackingFields.RequiredVersion())), ((SyntaxNode)current.Target).Location);
|
|
}
|
|
}
|
|
}
|
|
}
|