Open sandboxFocus

Struct TypedConstant

Represents a typed value that can be defined, defined to null, or undefined. Used to represent default values, for instance DefaultValue, or attribute arguments.

Namespace: Metalama.Framework.Code
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public readonly struct TypedConstant : IExpression, IHasType, IEquatable<TypedConstant>

Properties

Name Description
HasNullForgivingOperator

Gets a value indicating whether the null-forgiving operator (!) should be appended when this TypedConstant is rendered to code. Only applicable when IsNullOrDefault is true.

IsArray
IsInitialized

Gets a value indicating whether the Value has been specified (including when it is set to null).

IsNullOrDefault

Gets a value indicating whether the value is null or default. Not to be confused with IsInitialized.

RawValue

Gets the raw value of the TypedConstant. If IsArray is true, this property returns an ImmutableArray<TypedConstant>.

Type

Gets the type of the value. This is important if the type is an enum, because in this case, if the enum type is not compile-time, Value is set to the underlying integer value.

Value

Gets the Value for non-array types. For array types, get an array of a primitive type (e.g. int[]) instead of an array of TypedConstant.

Values

Methods

Name Description
Create(IField)

Creates a TypedConstant that references a constant field. When rendered to code, this produces a reference to the field (e.g., MyClass.MyConstField) instead of the literal value.

Create(object?)
Create(object?, IType?)
Create(object?, Type?)
CreateUnchecked(object?, IType)
Default(IType, bool)

Creates a TypedConstant representing the default value for the specified type. When rendered to code, this produces default(T) or default(T)! if hasNullForgivingOperator is true.

Default(Type, bool)

Creates a TypedConstant representing the default value for the specified type. When rendered to code, this produces default(T) or default(T)! if hasNullForgivingOperator is true.

Equals(TypedConstant)
Equals(object?)
ForCompilation(ICompilation)
GetHashCode()
ToString()
TryConvertFromExpression(IExpression, out TypedConstant?)
TryConvertFromExpression(string, out TypedConstant?)

Operators

Name Description
operator ==(TypedConstant, TypedConstant)
operator !=(TypedConstant, TypedConstant)

Extension Methods

See Also