Field
A Field is a member of a Class object which holds data.   Fields may also be members of Enum objects, but this is usually handled in the background by DotNetPELib.   In some cases, it is possible to generate a field directly into an AssemblyDef object, however, such fields cannot be accessed from other assemblies.

A Field would be constructed either directly, or through the Allocator object.   It might also be constructed indirectly, when constructing an enumerated value with functions in the Enum object.   All fields have a Type indicating what sort of data is stored in the Field.

        Field::Field(std::string Name, Type *tp, Qualifiers Flags) ;

A field can have a value.   Usually, an enumerated value would be added through calls in the Enum object.   Other types of binary initializers may be added; for example occil uses initialization values to support constant strings in the C language.  Initializer values are currently stored in managed memory (Older versions of the library stored them in unmanaged memory).

        enum ValueSize { i8, i16, i32, i64 };
        void AddEnumValue(longlong Value, ValueSize Size);

        void AddInitializer(Byte *bytes, int len);

Get the name of the field.

        const std::string &Name() const { return name_; }

Get/Set the name of the parent class.   It is usually set automatically when the Field is added to the Class.

        void SetContainer(DataContainer *Parent) { parent_ = Parent; }

        DataContainer *GetContainer() const { return parent_; }

Get/Set the field's type.

        Type *FieldType() const { return type_; }
        void FieldType(Type *tp) { type_ = tp; }

Get the CIL qualifiers

        const Qualifiers &Flags() const { return flags_; }

Not currently used.

        void Ref(bool Ref) { ref_ = Ref; }
        bool IsRef() const { return ref_; }

Get/set the 'external' flag (used by the linker)

        void External(bool external) { external_ = External; }
        bool External() const { return external_; }

Get/Set the field's .NET explicit offset.   For example set the class qualifiers to 'explicit' and then set all its fields to an explicitOffset of zero to make a union.   explicitOffsets may also be used for 'sequential' classes.

        void ExplicitOffset(size_t offset) { explicitOffset_ = offset;}
        size_t ExplicitOffset() const { return explicitOffset_; }