protected override void Initialize(TypeDefKey key) { Debug.Assert(key.Type.IsEnum && key is TypeDefKeyWithUnmanagedType); Type type = key.Type; this.name = Utility.GetNameOfType(type); this.isFlagsEnum = type.IsDefined(typeof(FlagsAttribute), false); UnmanagedType underlying_unmng_type = ((TypeDefKeyWithUnmanagedType)key).UnmanagedType; TypeName type_name = TypeName.GetTypeNameForUnmanagedType(underlying_unmng_type); // The unmanaged type has been validated by EnumNativeType and is surely a primitive type, for // which there is a simple direct translation to TypeName. Debug.Assert(!type_name.IsEmpty); this.underlyingType = new PrimitiveNativeType( type_name, (key.Flags & MarshalFlags.Platform64Bit) == MarshalFlags.Platform64Bit); // now enumerate the enum fields and set up the fields array string[] names = Enum.GetNames(type); Array values = Enum.GetValues(type); Debug.Assert(names.Length == values.Length); this.fields = new EnumField[values.Length]; for (int i = 0; i < values.Length; i++) { this.fields[i] = new EnumField(names[i], values.GetValue(i)); } }
protected override void Initialize(TypeDefKey key) { Debug.Assert(typeof(Delegate).IsAssignableFrom(key.Type)); base.Initialize(key); // create the native signature of the delegate signature = NativeSignature.FromDelegateType( key.Type, (key.Flags & MarshalFlags.AnsiPlatform) == MarshalFlags.AnsiPlatform, platform64bit); name = signature.Name; }
protected override void Initialize(TypeDefKey key) { if (key == null) throw new ArgumentNullException(nameof(key)); Debug.Assert(typeof(Delegate).IsAssignableFrom(key.Type)); base.Initialize(key); // create the native signature of the delegate signature = NativeSignature.FromDelegateType( key.Type, (key.Flags & MarshalFlags.AnsiPlatform) == MarshalFlags.AnsiPlatform, platform64bit); name = signature.Name; }
protected override void Initialize(TypeDefKey key) { if (key == null) throw new ArgumentNullException(nameof(key)); Debug.Assert(typeof(Delegate).IsAssignableFrom(key.Type)); base.Initialize(key); }
protected override void Initialize(TypeDefKey key) { Type type = key.Type; Debug.Assert(type.IsValueType || Utility.HasLayout(type)); this.name = Utility.GetNameOfType(type); this.isBlittable = Utility.IsStructBlittable(type, (key.Flags & MarshalFlags.AnsiPlatform) == MarshalFlags.AnsiPlatform); // reflect the structure FieldInfo[] fis = type.GetFields(bindingFlags); this.fields = new NativeField[fis.Length]; KeyValuePair <int, NativeField>[] fields_with_tokens = new KeyValuePair <int, NativeField> [fis.Length]; MarshalFlags flags = key.Flags & ~(MarshalFlags.AnsiStrings | MarshalFlags.UnicodeStrings); flags |= Utility.GetCharSetMarshalFlag(type); for (int i = 0; i < fis.Length; i++) { NativeField nf = NativeField.FromClrField(fis[i], flags); this.fields[i] = nf; // check for misaligned reference type fields // (can only be misaligned if layout was specified explicitly) if (nf.Offset.HasValue && nf.ContainsManagedReference) { int ptr_size = TypeName.GetPointerSize((key.Flags & MarshalFlags.Platform64Bit) == MarshalFlags.Platform64Bit); if (nf.Offset.Value % ptr_size != 0) { Log.Add(Errors.ERROR_MisalignedReferenceTypeField, nf.Name); } } if (nf.Type.TypeSize == 0) { // this means that the field type is another structure whose size has not been set up // yet -> there are circular dependencies among structures this.isInvalid = true; Log.Add(Errors.ERROR_RecursiveStructureDeclaration, nf.Name); } if (type.IsExplicitLayout && !nf.Offset.HasValue) { Log.Add(Errors.ERROR_NoFieldOffsetInSequentialLayout, nf.Name); } fields_with_tokens[i] = new KeyValuePair <int, NativeField>(fis[i].MetadataToken, nf); } // sort fields to reflect the layout if (type.IsExplicitLayout) { this.isExplicitLayout = true; // explicit layout - sort according to offsets Array.Sort <KeyValuePair <int, NativeField>, NativeField>( fields_with_tokens, this.fields, ExplicitFieldComparer.Instance); // managed references overlapping with other fields are not checked here - such errors are // reported by the loader and assemblies containing these types are never loaded } else { // sequential layout - sort according to metadata tokens Array.Sort <KeyValuePair <int, NativeField>, NativeField>( fields_with_tokens, this.fields, SequentialFieldComparer.Instance); } SetupSizeAndAlignment(type); SetupIsUnionFlag(); }
protected override void Initialize(TypeDefKey key) { if (key == null) throw new ArgumentNullException(nameof(key)); Debug.Assert(key.Type.IsEnum && key is TypeDefKeyWithUnmanagedType); Type type = key.Type; this.name = Utility.GetNameOfType(type); this.isFlagsEnum = type.IsDefined(typeof(FlagsAttribute), false); UnmanagedType underlying_unmng_type = ((TypeDefKeyWithUnmanagedType)key).UnmanagedType; TypeName type_name = TypeName.GetTypeNameForUnmanagedType(underlying_unmng_type); // The unmanaged type has been validated by EnumNativeType and is surely a primitive type, for // which there is a simple direct translation to TypeName. Debug.Assert(!type_name.IsEmpty); this.underlyingType = new PrimitiveNativeType( type_name, (key.Flags & MarshalFlags.Platform64Bit) == MarshalFlags.Platform64Bit); // now enumerate the enum fields and set up the fields array string[] names = Enum.GetNames(type); Array values = Enum.GetValues(type); Debug.Assert(names.Length == values.Length); this.fields = new EnumField[values.Length]; for (int i = 0; i < values.Length; i++) { this.fields[i] = new EnumField(names[i], values.GetValue(i)); } }
protected override void Initialize(TypeDefKey key) { Debug.Assert(typeof(Delegate).IsAssignableFrom(key.Type)); base.Initialize(key); }