Open sandboxFocus

Class AttributeConstruction

Encapsulates the information necessary to create a custom attribute programmatically.

Inheritance
AttributeConstruction
Implements
Namespace: Metalama.Framework.Code.DeclarationBuilders
Assembly: Metalama.Framework.dll
Syntax
public sealed class AttributeConstruction : IAttributeData
Remarks

Use this class to create custom attributes when introducing them to declarations via IntroduceAttribute(IAdviser<IDeclaration>, IAttributeData, OverrideStrategy) or when adding them to introduced declarations via AddAttribute(AttributeConstruction).

The Create(IConstructor, IReadOnlyList<TypedConstant>?, IReadOnlyList<KeyValuePair<string, TypedConstant>>?) method creates an attribute by specifying an explicit constructor and strongly-typed TypedConstant arguments. The Create(Type, IReadOnlyList<object?>?, IReadOnlyList<KeyValuePair<string, object?>>?) and Create(INamedType, IReadOnlyList<object?>?, IReadOnlyList<KeyValuePair<string, object?>>?) overloads automatically find a suitable constructor based on the provided argument types.

To copy an existing attribute from the code model, use the IAttribute directly as it implements IAttributeData.

Properties

Name Description
Constructor

Gets the attribute constructor.

ConstructorArguments

Gets the constructor arguments.

NamedArguments

Gets the named arguments, i.e. the assigned fields and properties. Note that the order may be important in case of non-trivial property setters.

Type

Gets the attribute type.

Methods

Name Description
Create(IConstructor, IReadOnlyList<TypedConstant>?, IReadOnlyList<KeyValuePair<string, TypedConstant>>?)

Creates a new AttributeConstruction by explicitly specifying the constructor and strongly-typed arguments.

Create(INamedType, IReadOnlyList<object?>?, IReadOnlyList<KeyValuePair<string, object?>>?)

Creates a new AttributeConstruction by specifying the INamedType of the attribute. The method will attempt to find a suitable constructor.

Create(Type, IReadOnlyList<object?>?, IReadOnlyList<KeyValuePair<string, object?>>?)

Creates a new AttributeConstruction by specifying the reflection Type of the attribute. The method will attempt to find a suitable constructor.

Extension Methods

See Also