private void WriteField() { AddHeader( "Name", "Signature", "Attributes", "Marshalling", "Offset", "RVA" ); foreach (var handle in reader.FieldDefinitions) { var entry = reader.GetField(handle); int offset = entry.GetOffset(); AddRow( Literal(entry.Name), Literal(entry.Signature), EnumValue <int>(entry.Attributes), Literal(entry.GetMarshallingDescriptor()), offset >= 0 ? offset.ToString() : "n/a", entry.GetRelativeVirtualAddress().ToString() ); } WriteRows("Field (0x04):"); }
private MemberInfo GetOrAddFieldInfo(FieldHandle handle) { if (this.fields == null) { this.fields = new Dictionary <FieldHandle, MemberInfo>(); } MemberInfo result = null; if (!fields.TryGetValue(handle, out result)) { result = new MemberInfo(MemberKind.Field); var field = metadataReader.GetField(handle); result.Token = metadataReader.GetToken(handle); result.DeclaringTypeHandle = metadataReader.GetDeclaringType(handle); if (result.DeclaringTypeHandle.IsNil) { throw null; } result.Handle = handle; fields[handle] = result; } return(result); }
public static StringHandle[] GetFieldDefNames(this MetadataReader reader) { var builder = ArrayBuilder <StringHandle> .GetInstance(); foreach (var handle in reader.FieldDefinitions) { var def = reader.GetField(handle); builder.Add(def.Name); } return(builder.ToArrayAndFree()); }
public override ClassLayoutMetadata GetClassLayout() { ClassLayoutMetadata result; result.PackingSize = checked ((int)_typeDefinition.PackingSize); result.Size = checked ((int)_typeDefinition.Size); // Skip reading field offsets if this is not explicit layout if (IsExplicitLayout) { var fieldDefinitionHandles = _typeDefinition.Fields; var numInstanceFields = 0; foreach (var handle in fieldDefinitionHandles) { var fieldDefinition = MetadataReader.GetField(handle); if ((fieldDefinition.Flags & FieldAttributes.Static) != 0) { continue; } numInstanceFields++; } result.Offsets = new FieldAndOffset[numInstanceFields]; int index = 0; foreach (var handle in fieldDefinitionHandles) { var fieldDefinition = MetadataReader.GetField(handle); if ((fieldDefinition.Flags & FieldAttributes.Static) != 0) { continue; } // Note: GetOffset() returns -1 when offset was not set in the metadata int fieldOffsetInMetadata = (int)fieldDefinition.Offset; LayoutInt fieldOffset = fieldOffsetInMetadata == -1 ? FieldAndOffset.InvalidOffset : new LayoutInt(fieldOffsetInMetadata); result.Offsets[index] = new FieldAndOffset(_metadataUnit.GetField(handle, this), fieldOffset); index++; } } else { result.Offsets = null; } return(result); }
/// <summary> /// Try to figure out field access information based on type metadata for native format types. /// </summary> /// <param name="metadataReader">Metadata reader for the declaring type</param> /// <param name="declaringTypeHandle">Declaring type for the method</param> /// <param name="fieldHandle">Field handle</param> /// <param name="canonFormKind">Canonical form to use</param> /// <param name="fieldAccessMetadata">Output - metadata information for field accessor construction</param> /// <returns>true when found, false otherwise</returns> private static bool TryGetFieldAccessMetadataFromNativeFormatMetadata( MetadataReader metadataReader, RuntimeTypeHandle declaringTypeHandle, FieldHandle fieldHandle, TypeSystemContext context, ref FieldAccessMetadata fieldAccessMetadata) { Field field = metadataReader.GetField(fieldHandle); string fieldName = metadataReader.GetString(field.Name); TypeDesc declaringType = context.ResolveRuntimeTypeHandle(declaringTypeHandle); #if SUPPORTS_NATIVE_METADATA_TYPE_LOADING if (declaringType is MetadataType) { return(TryGetFieldAccessMetadataForNativeFormatType(declaringType, fieldName, ref fieldAccessMetadata)); } #endif return(false); }
public override bool HasCustomAttribute(string attributeNamespace, string attributeName) { return(MetadataReader.HasCustomAttribute(MetadataReader.GetField(_handle).CustomAttributes, attributeNamespace, attributeName)); }
public static StringHandle[] GetFieldDefNames(this MetadataReader reader) { return(reader.FieldDefinitions.Select(handle => reader.GetField(handle).Name).ToArray()); }