I ask again. I'm trying emit this:
<-----------------------------
public class Test13_ConstLiteral
{
    enum LiteralEnum : long
    {
        one, two
    }
const Test13_ConstLiteral.LiteralEnum en =
Test13_ConstLiteral.LiteralEnum.two;
}
----------------------------->
by using Refelction.Emit. It's not important if this Enum type is nested or
not. Problem is when:
- field is literal
- type of field is enum type
- this enum type is emitted in the same assembly

Here is my pseudoCode:
<-------------------------------
....
FieldBuilder fb = ....
object val = FieldInfo.GetValue(new object())
TypeBuilder newTypeOfValue = xxx.defineType(..);
...
newTypeOfValue.CreateType()
..
string stringVal = val.ToString();
fb.SetConstant(Enum.Parse(newTypeOfValue, stringVal));
.........
------------------------------->
I've got exception (during SetConstant)
type of exception = System.ArgumentException
StackTrace = "at System.Enum.Parse(Type enumType, String value, Boolean
ignoreCase)
   at System.Enum.Parse(Type enumType, String value)
   at mycode.cs:line 240"
Message "Type must be a type provided by the runtime, not a TypeDelegator,
etc. Parameter name: enumType"

Of course I invoke CreateType() on this new TypeBuilder() , but it's not
important if typebuilder.m_hasBeenCreated is true or false;

Any idea how emit this literals?

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to