Class Constant
- Namespace
- AsmResolver.DotNet
- Assembly
- AsmResolver.DotNet.dll
Represents a literal value that is assigned to a field, parameter or property.
public class Constant : MetadataMember, IMetadataMember
- Inheritance
-
Constant
- Implements
- Derived
- Inherited Members
Constructors
Constant(ElementType, DataBlobSignature?)
Creates a new constant for a member, with the provided constant type and raw literal value.
public Constant(ElementType type, DataBlobSignature? value)
Parameters
typeElementTypeThe type of the constant.
valueDataBlobSignatureThe raw literal value of the constant.
Constant(MetadataToken)
Initializes the constant with a metadata token.
protected Constant(MetadataToken token)
Parameters
tokenMetadataTokenThe metadata token.
Properties
Parent
Gets the member that is assigned a constant.
public IHasConstant? Parent { get; }
Property Value
Type
Gets the type of constant that is stored in the blob stream.
public ElementType Type { get; set; }
Property Value
Remarks
This field must always be a value-type.
Value
Gets or sets the serialized literal value.
public DataBlobSignature? Value { get; set; }
Property Value
Methods
FromDefault(TypeSignature)
Create a Constant representing a default value
public static Constant FromDefault(TypeSignature type)
Parameters
typeTypeSignatureThe type of the new constant.
Returns
FromDefault(ElementType)
Create a Constant representing a default value
public static Constant FromDefault(ElementType elementType)
Parameters
elementTypeElementTypeThe type of the new constant.
Returns
FromNull()
Create a Constant representing a null reference
public static Constant FromNull()
Returns
Remarks
This can be used for any non-primitive default value.
FromValue(bool)
Create a Constant from a value
public static Constant FromValue(bool value)
Parameters
valueboolThe value to be assigned to the constant
Returns
FromValue(byte)
Create a Constant from a value
public static Constant FromValue(byte value)
Parameters
valuebyteThe value to be assigned to the constant
Returns
FromValue(char)
Create a Constant from a value
public static Constant FromValue(char value)
Parameters
valuecharThe value to be assigned to the constant
Returns
FromValue(double)
Create a Constant from a value
public static Constant FromValue(double value)
Parameters
valuedoubleThe value to be assigned to the constant
Returns
FromValue(short)
Create a Constant from a value
public static Constant FromValue(short value)
Parameters
valueshortThe value to be assigned to the constant
Returns
FromValue(int)
Create a Constant from a value
public static Constant FromValue(int value)
Parameters
valueintThe value to be assigned to the constant
Returns
FromValue(long)
Create a Constant from a value
public static Constant FromValue(long value)
Parameters
valuelongThe value to be assigned to the constant
Returns
FromValue(nint)
Create a Constant from a value
public static Constant FromValue(nint value)
Parameters
valuenintThe value to be assigned to the constant
Returns
FromValue(sbyte)
Create a Constant from a value
public static Constant FromValue(sbyte value)
Parameters
valuesbyteThe value to be assigned to the constant
Returns
FromValue(float)
Create a Constant from a value
public static Constant FromValue(float value)
Parameters
valuefloatThe value to be assigned to the constant
Returns
FromValue(string?)
Create a Constant from a value
public static Constant FromValue(string? value)
Parameters
valuestringThe value to be assigned to the constant
Returns
FromValue(ushort)
Create a Constant from a value
public static Constant FromValue(ushort value)
Parameters
valueushortThe value to be assigned to the constant
Returns
FromValue(uint)
Create a Constant from a value
public static Constant FromValue(uint value)
Parameters
valueuintThe value to be assigned to the constant
Returns
FromValue(ulong)
Create a Constant from a value
public static Constant FromValue(ulong value)
Parameters
valueulongThe value to be assigned to the constant
Returns
FromValue(nuint)
Create a Constant from a value
public static Constant FromValue(nuint value)
Parameters
valuenuintThe value to be assigned to the constant
Returns
GetParent()
Obtains the owner of the constant.
protected virtual IHasConstant? GetParent()
Returns
- IHasConstant
The parent.
Remarks
This method is called upon initialization of the Parent property.
GetValue()
Obtains the literal value of the constant.
protected virtual DataBlobSignature? GetValue()
Returns
- DataBlobSignature
The value.
Remarks
This method is called upon initialization of the Value property.
InterpretData()
Interprets the raw data stored in the Value property as a literal.
public object? InterpretData()
Returns
- object
The deserialized literal.