Table of Contents

Class FieldDefinition

Namespace
AsmResolver.DotNet
Assembly
AsmResolver.DotNet.dll

Represents a single field in a type definition of a .NET module.

public class FieldDefinition : MetadataMember, IMemberDefinition, IFieldDescriptor, IHasCustomAttribute, IHasConstant, IMemberForwarded, IMemberDescriptor, IFullNameProvider, IImportable, IHasFieldMarshal, IMetadataMember, INameProvider, IModuleProvider, IOwnedCollectionElement<TypeDefinition>
Inheritance
FieldDefinition
Implements
Derived
Inherited Members
Extension Methods

Constructors

FieldDefinition(MetadataToken)

Initializes a new field definition.

protected FieldDefinition(MetadataToken token)

Parameters

token MetadataToken

The token of the field.

FieldDefinition(Utf8String?, FieldAttributes, FieldSignature?)

Creates a new field definition.

public FieldDefinition(Utf8String? name, FieldAttributes attributes, FieldSignature? signature)

Parameters

name Utf8String

The name of the field.

attributes FieldAttributes

The attributes.

signature FieldSignature

The signature of the field.

FieldDefinition(Utf8String, FieldAttributes, TypeSignature?)

Creates a new field definition.

public FieldDefinition(Utf8String name, FieldAttributes attributes, TypeSignature? fieldType)

Parameters

name Utf8String

The name of the field.

attributes FieldAttributes

The attributes.

fieldType TypeSignature

The type of values the field contains.

Properties

Attributes

Gets or sets the attributes associated to the field.

public FieldAttributes Attributes { get; set; }

Property Value

FieldAttributes

Constant

Gets or sets a constant that is assigned to the member.

public Constant? Constant { get; set; }

Property Value

Constant

Remarks

If this property is set to null, the member is not assigned a constant value.

Updating this property does not update any of the attributes associated to the member.

CustomAttributes

Gets a collection of custom attributes assigned to this member.

public IList<CustomAttribute> CustomAttributes { get; }

Property Value

IList<CustomAttribute>

DeclaringType

Gets the type that defines the field.

public TypeDefinition? DeclaringType { get; }

Property Value

TypeDefinition

FieldOffset

Gets or sets the explicit offset of the field, relative to the starting address of the object (if available).

public int? FieldOffset { get; set; }

Property Value

int?

FieldRva

Gets or sets a segment containing the initial value of the field.

public ISegment? FieldRva { get; set; }

Property Value

ISegment

Remarks

Updating this property does not automatically update the HasFieldRva property, nor does the value of HasFieldRva reflect whether the field has initialization data or not. Well-formed .NET binaries should always set the HasFieldRva flag to true if this property is non-null.

FullName

Gets the full name of the object.

public string FullName { get; }

Property Value

string

HasDefault

Gets or sets a value indicating whether the field has a default value associated to it.

public bool HasDefault { get; set; }

Property Value

bool

HasFieldMarshal

Gets or sets a value indicating whether the field has marshalling information associated to it.

public bool HasFieldMarshal { get; set; }

Property Value

bool

HasFieldRva

Gets or sets a value indicating whether the field has an initial value associated to it that is referenced by a relative virtual address.

public bool HasFieldRva { get; set; }

Property Value

bool

ImplementationMap

Gets or sets the Platform Invoke (P/Invoke) implementation mapping of this member (if available).

public ImplementationMap? ImplementationMap { get; set; }

Property Value

ImplementationMap

IsAssembly

Gets or sets a value indicating whether the field is marked private and can only be accessed by members within the same assembly.

public bool IsAssembly { get; set; }

Property Value

bool

IsFamily

Gets or sets a value indicating whether the field is marked private and can only be accessed by members within the same enclosing type, as well as any derived type.

public bool IsFamily { get; set; }

Property Value

bool

IsFamilyAndAssembly

Gets or sets a value indicating whether the field is marked family and assembly, and can only be accessed by members within the same enclosing type and any derived type, within the same assembly.

public bool IsFamilyAndAssembly { get; set; }

Property Value

bool

IsFamilyOrAssembly

Gets or sets a value indicating whether the field is marked family or assembly, and can only be accessed by members within the same enclosing type and any derived type, or within the same assembly.

public bool IsFamilyOrAssembly { get; set; }

Property Value

bool

IsInitOnly

Gets or sets a value indicating whether the field is marked init-only, and can only be assigned a value by a constructor of the enclosing type.

public bool IsInitOnly { get; set; }

Property Value

bool

IsLiteral

Gets or sets a value indicating whether the field is marked as a literal, and its value is decided upon compile time.

public bool IsLiteral { get; set; }

Property Value

bool

IsNotSerialized

Gets or sets a value indicating whether the field is marked as not serialized, indicating the field does not have to be serialized when the enclosing type is remoted.

public bool IsNotSerialized { get; set; }

Property Value

bool

IsPInvokeImpl

Gets or sets a value indicating whether the field's implementation is forwarded through Platform Invoke.

public bool IsPInvokeImpl { get; set; }

Property Value

bool

IsPrivate

Gets or sets a value indicating whether the field is marked private and can only be accessed by members within the same enclosing type.

public bool IsPrivate { get; set; }

Property Value

bool

IsPrivateScope

Gets or sets a value indicating whether the field is in a private scope.

public bool IsPrivateScope { get; set; }

Property Value

bool

IsPublic

Gets or sets a value indicating whether the field is marked public, and can be accessed by any member having access to the enclosing type.

public bool IsPublic { get; set; }

Property Value

bool

IsRuntimeSpecialName

Gets or sets a value indicating whether the field uses a name that is used by the runtime.

public bool IsRuntimeSpecialName { get; set; }

Property Value

bool

IsSpecialName

Gets or sets a value indicating whether the field uses a special name.

public bool IsSpecialName { get; set; }

Property Value

bool

IsStatic

Gets or sets a value indicating whether the field requires an object instance to access it.

public bool IsStatic { get; set; }

Property Value

bool

Remarks

This property does not reflect the value of HasThis, nor will it change the value of HasThis if this property is changed. For a valid .NET image, these values should match, however.

MarshalDescriptor

Gets or sets the description on how a specific value needs to be marshaled upon calling to or from unmanaged code via P/Invoke dispatch.

public MarshalDescriptor? MarshalDescriptor { get; set; }

Property Value

MarshalDescriptor

Module

Gets the module that defines the member definition or reference.

public ModuleDefinition? Module { get; }

Property Value

ModuleDefinition

Remarks

For member references, this does not obtain the module definition that the member is defined in. Rather, it obtains the module definition that references this reference.

Name

Gets or sets the name of the field.

public Utf8String? Name { get; set; }

Property Value

Utf8String

Remarks

This property corresponds to the Name column in the field table.

Signature

Gets or sets the signature of the field. This includes the field type.

public FieldSignature? Signature { get; set; }

Property Value

FieldSignature

Methods

GetConstant()

Obtains the constant value assigned to the field definition.

protected virtual Constant? GetConstant()

Returns

Constant

The constant.

Remarks

This method is called upon initialization of the Constant property.

GetCustomAttributes()

Obtains the list of custom attributes assigned to the member.

protected virtual IList<CustomAttribute> GetCustomAttributes()

Returns

IList<CustomAttribute>

The attributes

Remarks

This method is called upon initialization of the CustomAttributes property.

GetDeclaringType()

Obtains the declaring type of the field definition.

protected virtual TypeDefinition? GetDeclaringType()

Returns

TypeDefinition

The declaring type.

Remarks

This method is called upon initialization of the DeclaringType property.

GetFieldOffset()

Obtains the offset of the field as defined in the field layout.

protected virtual int? GetFieldOffset()

Returns

int?

The field offset.

Remarks

This method is called upon initialization of the FieldOffset property.

GetFieldRva()

Obtains the initial value of the field.

protected virtual ISegment? GetFieldRva()

Returns

ISegment

The initial value.

Remarks

This method is called upon initialization of the FieldRva property.

GetImplementationMap()

Obtains the platform invoke information assigned to the field.

protected virtual ImplementationMap? GetImplementationMap()

Returns

ImplementationMap

The mapping.

Remarks

This method is called upon initialization of the ImplementationMap property.

GetMarshalDescriptor()

Obtains the marshal descriptor value assigned to the field definition.

protected virtual MarshalDescriptor? GetMarshalDescriptor()

Returns

MarshalDescriptor

The marshal descriptor.

Remarks

This method is called upon initialization of the MarshalDescriptor property.

GetName()

Obtains the name of the field definition.

protected virtual Utf8String? GetName()

Returns

Utf8String

The name.

Remarks

This method is called upon initialization of the Name property.

GetSignature()

Obtains the signature of the field definition.

protected virtual FieldSignature? GetSignature()

Returns

FieldSignature

The signature.

Remarks

This method is called upon initialization of the Signature property.

ImportWith(ReferenceImporter)

Imports the field using the provided reference importer object.

public IFieldDescriptor ImportWith(ReferenceImporter importer)

Parameters

importer ReferenceImporter

The reference importer to use.

Returns

IFieldDescriptor

The imported field.

IsAccessibleFromType(TypeDefinition)

Determines whether the member can be accessed from the scope that is determined by the provided type.

public bool IsAccessibleFromType(TypeDefinition type)

Parameters

type TypeDefinition

The type defining the scope.

Returns

bool

True if the scope of the provided type can access the member, false otherwise.

IsImportedInModule(ModuleDefinition)

Determines whether the descriptor of the member is fully imported in the provided module.

public bool IsImportedInModule(ModuleDefinition module)

Parameters

module ModuleDefinition

The module that is supposed to import the member.

Returns

bool

true if the descriptor of the member is fully imported by the module, false otherwise.

Remarks

This method verifies all references in the descriptor of the member only. It does not verify any additional data or contents (such as a method body) associated to the member.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.