dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [DotGNU]Re: [Mono-list] Enum declaration; Conflicts and Blame for In


From: Jeroen Frijters
Subject: RE: [DotGNU]Re: [Mono-list] Enum declaration; Conflicts and Blame for Interoperability Problems
Date: Tue, 7 Jan 2003 15:24:36 +0100

Hmm, interesting. I just tried the following (on the MS CLR):

AssemblyName name = new AssemblyName();
name.Name = "test";
AssemblyBuilder asm = AppDomain.CurrentDomain.DefineDynamicAssembly(name,
AssemblyBuilderAccess.Save);
ModuleBuilder mod = asm.DefineDynamicModule("testmodule", "test.dll");
TypeBuilder enumBldr = mod.DefineType("MyEnum", TypeAttributes.Public,
typeof(Enum));
enumBldr.DefineField("value__", typeof(int), FieldAttributes.Private |
FieldAttributes.RTSpecialName | FieldAttributes.SpecialName);
enumBldr.DefineField("foo", enumBldr, FieldAttributes.Literal |
FieldAttributes.Public).SetConstant(1);
enumBldr.CreateType();
asm.Save("test.dll");

And this seems to work.

Regards,
Jeroen

> -----Original Message-----
> From: Paolo Molaro [mailto:address@hidden 
> Sent: Tuesday, January 07, 2003 15:10
> To: address@hidden; address@hidden
> Subject: [DotGNU]Re: [Mono-list] Enum declaration; Conflicts 
> and Blame for Interoperability Problems
> 
> 
> 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
> SetConstant).
> 
> lupus
> 
> -- 
> -----------------------------------------------------------------
> address@hidden                                     debian/rules
> address@hidden                             Monkeys do it better
> _______________________________________________
> Developers mailing list
> address@hidden
> http://www.dotgnu.org/mailman/listinfo/developers
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]