private void SetStructLayoutPseudoCustomAttribute(CustomAttributeBuilder customBuilder) { object val = customBuilder.GetConstructorArgument(0); LayoutKind layout; if (val is short) { layout = (LayoutKind)(short)val; } else { layout = (LayoutKind)val; } int?pack = (int?)customBuilder.GetFieldValue("Pack"); int?size = (int?)customBuilder.GetFieldValue("Size"); if (pack.HasValue || size.HasValue) { ClassLayoutTable.Record rec = new ClassLayoutTable.Record(); rec.PackingSize = (short)(pack ?? 0); rec.ClassSize = size ?? 0; rec.Parent = token; this.ModuleBuilder.ClassLayout.AddRecord(rec); } attribs &= ~TypeAttributes.LayoutMask; switch (layout) { case LayoutKind.Auto: attribs |= TypeAttributes.AutoLayout; break; case LayoutKind.Explicit: attribs |= TypeAttributes.ExplicitLayout; break; case LayoutKind.Sequential: attribs |= TypeAttributes.SequentialLayout; break; } CharSet?charSet = customBuilder.GetFieldValue <CharSet>("CharSet"); attribs &= ~TypeAttributes.StringFormatMask; switch (charSet ?? CharSet.None) { case CharSet.None: case CharSet.Ansi: attribs |= TypeAttributes.AnsiClass; break; case CharSet.Auto: attribs |= TypeAttributes.AutoClass; break; case CharSet.Unicode: attribs |= TypeAttributes.UnicodeClass; break; } }
private void PostDefineType(TypeBuilder typeBuilder, PackingSize packingSize, int typesize) { types.Add(typeBuilder); fullNameToType.Add(typeBuilder.FullName, typeBuilder); if (packingSize != PackingSize.Unspecified || typesize != 0) { ClassLayoutTable.Record rec = new ClassLayoutTable.Record(); rec.PackingSize = (short)packingSize; rec.ClassSize = typesize; rec.Parent = typeBuilder.MetadataToken; this.ClassLayout.AddRecord(rec); } }
public TypeInfo CreateTypeInfo() { if ((typeFlags & TypeFlags.Baked) != 0) { // .NET allows multiple invocations (subsequent invocations return the same baked type) throw new NotImplementedException(); } typeFlags |= TypeFlags.Baked; if (hasLayout) { ClassLayoutTable.Record rec = new ClassLayoutTable.Record(); rec.PackingSize = pack; rec.ClassSize = size; rec.Parent = token; this.ModuleBuilder.ClassLayout.AddRecord(rec); } bool hasConstructor = false; foreach (MethodBuilder mb in methods) { hasConstructor |= mb.IsSpecialName && mb.Name == ConstructorInfo.ConstructorName; mb.Bake(); } if (!hasConstructor && !IsModulePseudoType && !IsInterface && !IsValueType && !(IsAbstract && IsSealed) && Universe.AutomaticallyProvideDefaultConstructor) { ((MethodBuilder)DefineDefaultConstructor(MethodAttributes.Public).GetMethodInfo()).Bake(); } if (declarativeSecurity != null) { this.ModuleBuilder.AddDeclarativeSecurity(token, declarativeSecurity); } if (!IsModulePseudoType) { Type baseType = this.BaseType; if (baseType != null) { extends = this.ModuleBuilder.GetTypeToken(baseType).Token; } } if (interfaces != null) { foreach (Type interfaceType in interfaces) { InterfaceImplTable.Record rec = new InterfaceImplTable.Record(); rec.Class = token; rec.Interface = this.ModuleBuilder.GetTypeToken(interfaceType).Token; this.ModuleBuilder.InterfaceImpl.AddRecord(rec); } } return(new BakedType(this)); }
public Type CreateType() { if ((typeFlags & TypeFlags.Baked) != 0) { // .NET allows multiple invocations (subsequent invocations return the same baked type) throw new NotImplementedException(); } typeFlags |= TypeFlags.Baked; if (hasLayout) { ClassLayoutTable.Record rec = new ClassLayoutTable.Record(); rec.PackingSize = pack; rec.ClassSize = size; rec.Parent = token; this.ModuleBuilder.ClassLayout.AddRecord(rec); } foreach (MethodBuilder mb in methods) { mb.Bake(); } if (declarativeSecurity != null) { this.ModuleBuilder.AddDeclarativeSecurity(token, declarativeSecurity); } if (!IsModulePseudoType) { Type baseType = this.BaseType; if (baseType != null) { extends = this.ModuleBuilder.GetTypeToken(baseType).Token; } } if (interfaces != null) { foreach (Type interfaceType in interfaces) { InterfaceImplTable.Record rec = new InterfaceImplTable.Record(); rec.Class = token; rec.Interface = this.ModuleBuilder.GetTypeToken(interfaceType).Token; this.ModuleBuilder.InterfaceImpl.AddRecord(rec); } } return(new BakedType(this)); }
public Type CreateType() { if ((typeFlags & TypeFlags.Baked) != 0) { // .NET allows multiple invocations (subsequent invocations return the same baked type) throw new NotImplementedException(); } typeFlags |= TypeFlags.Baked; if (hasLayout) { ClassLayoutTable.Record rec = new ClassLayoutTable.Record(); rec.PackingSize = pack; rec.ClassSize = size; rec.Parent = token; this.ModuleBuilder.ClassLayout.AddRecord(rec); } foreach (MethodBuilder mb in methods) { mb.Bake(); } if (declarativeSecurity != null) { this.ModuleBuilder.AddDeclarativeSecurity(token, declarativeSecurity); } if (!IsModulePseudoType) { Type baseType = this.BaseType; if (baseType != null) { extends = this.ModuleBuilder.GetTypeToken(baseType).Token; } } if (interfaces != null) { foreach (Type interfaceType in interfaces) { InterfaceImplTable.Record rec = new InterfaceImplTable.Record(); rec.Class = token; rec.Interface = this.ModuleBuilder.GetTypeToken(interfaceType).Token; this.ModuleBuilder.InterfaceImpl.AddRecord(rec); } } return new BakedType(this); }
private void SetStructLayoutPseudoCustomAttribute(CustomAttributeBuilder customBuilder) { object val = customBuilder.GetConstructorArgument(0); LayoutKind layout; if (val is short) { layout = (LayoutKind)(short)val; } else { layout = (LayoutKind)val; } int? pack = (int?)customBuilder.GetFieldValue("Pack"); int? size = (int?)customBuilder.GetFieldValue("Size"); if (pack.HasValue || size.HasValue) { ClassLayoutTable.Record rec = new ClassLayoutTable.Record(); rec.PackingSize = (short)(pack ?? 0); rec.ClassSize = size ?? 0; rec.Parent = token; this.ModuleBuilder.ClassLayout.AddOrReplaceRecord(rec); } attribs &= ~TypeAttributes.LayoutMask; switch (layout) { case LayoutKind.Auto: attribs |= TypeAttributes.AutoLayout; break; case LayoutKind.Explicit: attribs |= TypeAttributes.ExplicitLayout; break; case LayoutKind.Sequential: attribs |= TypeAttributes.SequentialLayout; break; } CharSet? charSet = customBuilder.GetFieldValue<CharSet>("CharSet"); attribs &= ~TypeAttributes.StringFormatMask; switch (charSet ?? CharSet.None) { case CharSet.None: case CharSet.Ansi: attribs |= TypeAttributes.AnsiClass; break; case CharSet.Auto: attribs |= TypeAttributes.AutoClass; break; case CharSet.Unicode: attribs |= TypeAttributes.UnicodeClass; break; } }
public Type CreateType() { if ((typeFlags & TypeFlags.Baked) != 0) { // .NET allows multiple invocations (subsequent invocations return the same baked type) throw new NotImplementedException(); } typeFlags |= TypeFlags.Baked; if (hasLayout) { ClassLayoutTable.Record rec = new ClassLayoutTable.Record(); rec.PackingSize = pack; rec.ClassSize = size; rec.Parent = token; this.ModuleBuilder.ClassLayout.AddRecord(rec); } bool hasConstructor = false; foreach (MethodBuilder mb in methods) { hasConstructor |= mb.IsSpecialName && mb.Name == ConstructorInfo.ConstructorName; mb.Bake(); } if (!hasConstructor && !IsModulePseudoType && !IsInterface && !IsValueType && !(IsAbstract && IsSealed)) { ((MethodBuilder)DefineDefaultConstructor(MethodAttributes.Public).GetMethodInfo()).Bake(); } if (declarativeSecurity != null) { this.ModuleBuilder.AddDeclarativeSecurity(token, declarativeSecurity); } if (!IsModulePseudoType) { Type baseType = this.BaseType; if (baseType != null) { extends = this.ModuleBuilder.GetTypeToken(baseType).Token; } } if (interfaces != null) { foreach (Type interfaceType in interfaces) { InterfaceImplTable.Record rec = new InterfaceImplTable.Record(); rec.Class = token; rec.Interface = this.ModuleBuilder.GetTypeToken(interfaceType).Token; this.ModuleBuilder.InterfaceImpl.AddRecord(rec); } } return new BakedType(this); }