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
type
ElementTypeThe type of the constant.
value
DataBlobSignatureThe raw literal value of the constant.
Constant(MetadataToken)
Initializes the constant with a metadata token.
protected Constant(MetadataToken token)
Parameters
token
MetadataTokenThe 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
type
TypeSignatureThe type of the new constant.
Returns
FromDefault(ElementType)
Create a Constant representing a default value
public static Constant FromDefault(ElementType elementType)
Parameters
elementType
ElementTypeThe 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
value
boolThe value to be assigned to the constant
Returns
FromValue(byte)
Create a Constant from a value
public static Constant FromValue(byte value)
Parameters
value
byteThe value to be assigned to the constant
Returns
FromValue(char)
Create a Constant from a value
public static Constant FromValue(char value)
Parameters
value
charThe value to be assigned to the constant
Returns
FromValue(double)
Create a Constant from a value
public static Constant FromValue(double value)
Parameters
value
doubleThe value to be assigned to the constant
Returns
FromValue(short)
Create a Constant from a value
public static Constant FromValue(short value)
Parameters
value
shortThe value to be assigned to the constant
Returns
FromValue(int)
Create a Constant from a value
public static Constant FromValue(int value)
Parameters
value
intThe value to be assigned to the constant
Returns
FromValue(long)
Create a Constant from a value
public static Constant FromValue(long value)
Parameters
value
longThe value to be assigned to the constant
Returns
FromValue(nint)
Create a Constant from a value
public static Constant FromValue(nint value)
Parameters
value
nintThe value to be assigned to the constant
Returns
FromValue(sbyte)
Create a Constant from a value
public static Constant FromValue(sbyte value)
Parameters
value
sbyteThe value to be assigned to the constant
Returns
FromValue(float)
Create a Constant from a value
public static Constant FromValue(float value)
Parameters
value
floatThe value to be assigned to the constant
Returns
FromValue(string?)
Create a Constant from a value
public static Constant FromValue(string? value)
Parameters
value
stringThe value to be assigned to the constant
Returns
FromValue(ushort)
Create a Constant from a value
public static Constant FromValue(ushort value)
Parameters
value
ushortThe value to be assigned to the constant
Returns
FromValue(uint)
Create a Constant from a value
public static Constant FromValue(uint value)
Parameters
value
uintThe value to be assigned to the constant
Returns
FromValue(ulong)
Create a Constant from a value
public static Constant FromValue(ulong value)
Parameters
value
ulongThe value to be assigned to the constant
Returns
FromValue(nuint)
Create a Constant from a value
public static Constant FromValue(nuint value)
Parameters
value
nuintThe 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.