using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.CSharp.Symbols; internal sealed class SynthesizedEmbeddedNativeIntegerAttributeSymbol : SynthesizedEmbeddedAttributeSymbolBase { private readonly ImmutableArray _fields; private readonly ImmutableArray _constructors; private readonly TypeSymbol _boolType; private const string FieldName = "TransformFlags"; public override ImmutableArray Constructors => _constructors; public SynthesizedEmbeddedNativeIntegerAttributeSymbol(string name, NamespaceSymbol containingNamespace, ModuleSymbol containingModule, NamedTypeSymbol systemAttributeType, TypeSymbol boolType) : base(name, containingNamespace, containingModule, systemAttributeType) { _boolType = boolType; TypeWithAnnotations boolArrayType = TypeWithAnnotations.Create(ArrayTypeSymbol.CreateSZArray(boolType.ContainingAssembly, TypeWithAnnotations.Create(boolType))); _fields = ImmutableArray.Create((FieldSymbol)new SynthesizedFieldSymbol(this, boolArrayType.Type, "TransformFlags", isPublic: true, isReadOnly: true)); _constructors = ImmutableArray.Create((MethodSymbol)new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(this, (MethodSymbol m) => ImmutableArray.Empty, delegate(SyntheticBoundNodeFactory f, ArrayBuilder s, ImmutableArray p) { GenerateParameterlessConstructorBody(f, s); }), (MethodSymbol)new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(this, (MethodSymbol m) => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, boolArrayType, 0, (RefKind)0, "", (ScopedKind)0)), delegate(SyntheticBoundNodeFactory f, ArrayBuilder s, ImmutableArray p) { GenerateBoolArrayConstructorBody(f, s, p); })); } internal override IEnumerable GetFieldsToEmit() { return _fields; } internal override AttributeUsageInfo GetAttributeUsageInfo() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return new AttributeUsageInfo(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, false, false); } private void GenerateParameterlessConstructorBody(SyntheticBoundNodeFactory factory, ArrayBuilder statements) { statements.Add((BoundStatement)factory.ExpressionStatement(factory.AssignmentExpression(factory.Field(factory.This(), _fields.Single()), factory.Array(_boolType, ImmutableArray.Create((BoundExpression)factory.Literal(value: true)))))); } private void GenerateBoolArrayConstructorBody(SyntheticBoundNodeFactory factory, ArrayBuilder statements, ImmutableArray parameters) { statements.Add((BoundStatement)factory.ExpressionStatement(factory.AssignmentExpression(factory.Field(factory.This(), _fields.Single()), factory.Parameter(parameters.Single())))); } }