Have you tried using typeof(ValueType) as the parent? At the IL level,
both struct and class are IL classes - i.e. here is the sig from Int32
(IL view in reflector):
.class public sequential ansi serializable sealed beforefieldinit
Int32
extends System.ValueType
implements System.IComparable, System.IFormattable,
System.IConvertible, System.IComparable`1<int32>,
System.IEquatable`1<int32>
That seems to work - at least in a quick test CreateType().IsValueType
returned true.
Of course, you still might have some fun getting this new Type into
your external API...
Marc
Marc Gravell - 13 Mar 2008 14:08 GMT
(example)
AssemblyName an = new AssemblyName("Foo");
AssemblyBuilder ab =
AppDomain.CurrentDomain.DefineDynamicAssembly(an,
AssemblyBuilderAccess.Run);
ModuleBuilder mb = ab.DefineDynamicModule("Foo");
TypeBuilder tb = mb.DefineType("Foo", TypeAttributes.Public |
TypeAttributes.Sealed | TypeAttributes.SequentialLayout |
TypeAttributes.Serializable, typeof(ValueType));
Type type = tb.CreateType();
bool isVal = type.IsValueType;
Marek - 13 Mar 2008 14:22 GMT
Hi Marc
You're a star. That worked a treat thanks.
Nice use of the parent type parameter - I looked at it but didn't think of
using it in this way.
Best regards
Marek
> (example)
>
[quoted text clipped - 8 lines]
> Type type = tb.CreateType();
> bool isVal = type.IsValueType;