private static TypeBuilder CreateTypeFromSpecification(this ModuleBuilder moduleBuilder, TypeSpecification typeSpec) { return moduleBuilder.DefineType( typeSpec.Name, typeSpec.TypeAttributes, typeSpec.ParentType); }
private static void AddTypeAttributes(TypeBuilder typeBuilder, TypeSpecification typeSpec) { foreach (var attributeTemplate in typeSpec.Attributes) { if (typeSpec.BeforeAttributeIsAddedToType != null) typeSpec.BeforeAttributeIsAddedToType(attributeTemplate.Template, typeBuilder); typeBuilder.AddAttribute(attributeTemplate); } }
public static Type CreateClass( this ModuleBuilder moduleBuilder, Action<TypeSpecification> typeSpecificationExpression) { TypeSpecification typeSpec = new TypeSpecification(); typeSpecificationExpression(typeSpec); TypeBuilder typeBuilder = moduleBuilder.CreateTypeFromSpecification(typeSpec); AddTypeAttributes(typeBuilder, typeSpec); AddProperties(typeBuilder, typeSpec.Properties); return typeBuilder.CreateType(); }
private static TypeBuilder CreateTypeFromSpecification(this ModuleBuilder moduleBuilder, TypeSpecification typeSpec) { return(moduleBuilder.DefineType( typeSpec.Name, typeSpec.TypeAttributes, typeSpec.ParentType, typeSpec.Interfaces.ToArray())); }