[Mono-list] Enum declaration; Conflicts and Blame for Interoperability Problems

Paolo Molaro lupus@ximian.com
Tue, 7 Jan 2003 15:10:28 +0100

On 01/07/03 Jeroen Frijters wrote:
> > The underlying issue, though, is that with the 
> > Reflection.Emit API it's not possible to create enums as
> > produced by csc. Once portable.net
> > will implement Reflection.Emit, it'll have to support this 
> > stuff anyway, just like the MS runtime does.
> ... I would argue that MS's EnumBuilder.DefineLiteral is broken. It would be
> best if it allowed both using the underlying type as well as the enum type,
> but the current behavior as the only option is *not* acceptable (given that
> it is not CLS compliant).

I don't know off-hand what DefineLiteral accepts. The issue is that you
can't use EnumBuilder in all cases, so mcs doesn't use it and it
'constructs' the enum type by hand. The reason is that an API
is missing (though it's documented): TypeBuilder.DefineNestedEnum().

So the process is to create a TypeBuilder and then DefineField()
as needed. The value of the enum is set with FieldBuilder.SetConstant().
I think SetConstant() accepts values of the underlying type of the enum,
but it can't accept constants of the type itself, because that would
imply calling CreateType() on the enum type (and hence it wouldn't be
possible anymore to create fields in it and set their value with


lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better