public FieldMetadataICodeElementAdapter(Field field, TypeDefinition typeDefinition, IList<TypeDescriptor> genericTypes, MetadataReader reader)
            : base(typeDefinition, genericTypes, reader)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            this.Field = field;
        }
        public Field GetFieldProperties(int token)
        {
            // The Field's name will be stored in this array. The 1024 is a "magical number", seems like a type's name can be maximum this long. The corhlpr.h also defines a suspicious constant like this: #define MAX_CLASSNAME_LENGTH 1024
            var fieldName = new char[1024];

            var typeDefToken = 0;

            // Number of how many characters were filled in the typeName array.
            var nameLength = 0;

            // Field's flags.
            var attr = 0;

            // A pointer to the binary metadata signature of the Field.
            var sigBlob = new IntPtr(0);

            var sigBlobLength = 0;

            // A pointer to the relative virtual address of the Field.
            var codeRva = 0;

            // A constant string value returned by this member.
            var value = new IntPtr(0);

            var valueLength = 0;

            // Get the Field's properties.
            var hresult = this.import.GetFieldProps(
                token,
                ref typeDefToken,
                fieldName,
                fieldName.Length,
                ref nameLength,
                ref attr,
                ref sigBlob,
                ref sigBlobLength,
                ref codeRva,
                ref value,
                ref valueLength);
            if (hresult != 0)
            {
                Marshal.ThrowExceptionForHR(hresult);
            }

            // supress names "" & "\0";
            if (nameLength <= 1)
            {
                // return null for this, we do not need to know about empty base
                return null;
            }

            // Get the Field's name.
            var fullTypeName = new string(fieldName, 0, nameLength - 1);

            var sigBlobBytes = new byte[sigBlobLength];
            for (var byteIndex = 0; byteIndex < sigBlobLength; byteIndex++)
            {
                sigBlobBytes[byteIndex] = Marshal.ReadByte(sigBlob, byteIndex);
            }

            var valueBytes = new byte[valueLength];
            for (var byteIndex = 0; byteIndex < valueLength; byteIndex++)
            {
                valueBytes[byteIndex] = Marshal.ReadByte(value, byteIndex);
            }

            var fieldProperties = new Field
                {
                    Token = token,
                    FullName = fullTypeName,
                    Flags = (CorFieldAttr)attr,
                    SigBlob = sigBlobBytes,
                    CodeRva = codeRva,
                    Value = valueBytes
                };

            return fieldProperties;
        }