Enum and FlagsAttribute

N

Nicolas

How do I set a FlagsAttribute to a run time created enum
I really need a FlagsAttribute for the enum as it will be use to trigger multiple choice
Thanks for the help
Function BuildEnum(ByVal EnumName As String, ByVal args As Hashtable) As Type
Dim ad As AppDomain
Dim an As New AssemblyName
Dim ab As AssemblyBuilder
Dim mb As ModuleBuilder
Dim eb As EnumBuilder
Dim t As Type
Dim ie As IDictionaryEnumerator = args.GetEnumerator

Try
ad = AppDomain.CurrentDomain
an.Name = EnumName
ab = ad.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave)
mb = ab.DefineDynamicModule(EnumName, EnumName & ".dll")
eb = mb.DefineEnum(EnumName, TypeAttributes.Public, GetType(Integer))

While ie.MoveNext
eb.DefineLiteral(ie.Value, CInt(ie.Key))
End While

t = eb.CreateType()
Return t

Catch ex As Exception
''do nothing
Return Nothing

Finally

End Try
End Function
 
M

Mattias Sjögren

How do I set a FlagsAttribute to a run time created enum

Something like this:

eb.SetCustomAttribute(New
CustomAttributeBuilder(GetType(FlagsAttribute).GetConstructor(Type.EmptyTypes),
New Object() {}))


Mattias
 
N

Nicolas

You'r my man thanks a lot :)

Mattias Sjögren said:
Something like this:

eb.SetCustomAttribute(New
CustomAttributeBuilder(GetType(FlagsAttribute).GetConstructor(Type.EmptyType
s),
New Object() {}))


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top