Enum and FlagsAttribute

  • Thread starter Thread starter Nicolas
  • Start date Start date
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
 
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
 
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
 
Back
Top