object CreateTypeBuilder(TypeDefinition type)
{
Type baseType = null;
if (IsEnumDefinition(type))
{
baseType = typeof(Enum);
}
else if (IsValueType(type))
{
baseType = Types.ValueType;
}
TypeBuilder typeBuilder = null;
var enclosingType = type.ParentNode as ClassDefinition;
var enumDef = type as EnumDefinition;
if (null == enclosingType)
{
typeBuilder = _moduleBuilder.DefineType(
AnnotateGenericTypeName(type, type.QualifiedName),
GetTypeAttributes(type),
baseType);
}
else
{
typeBuilder = GetTypeBuilder(enclosingType).DefineNestedType(
AnnotateGenericTypeName(type, type.Name),
GetNestedTypeAttributes(type),
baseType);
}
if (IsEnumDefinition(type))
{
// Mono cant construct enum array types unless
// the fields is already defined
typeBuilder.DefineField("value__",
GetEnumUnderlyingType(enumDef),
FieldAttributes.Public |
FieldAttributes.SpecialName |
FieldAttributes.RTSpecialName);
}
return typeBuilder;
}