473,624 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enum and FlagsAttribute

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 IDictionaryEnum erator = args.GetEnumera tor

Try
ad = AppDomain.Curre ntDomain
an.Name = EnumName
ab = ad.DefineDynami cAssembly(an, AssemblyBuilder Access.RunAndSa ve)
mb = ab.DefineDynami cModule(EnumNam e, EnumName & ".dll")
eb = mb.DefineEnum(E numName, TypeAttributes. Public, GetType(Integer ))

While ie.MoveNext
eb.DefineLitera l(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
Mar 9 '06 #1
2 1680
>How do I set a FlagsAttribute to a run time created enum

Something like this:

eb.SetCustomAtt ribute(New
CustomAttribute Builder(GetType (FlagsAttribute ).GetConstructo r(Type.EmptyTyp es),
New Object() {}))
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 9 '06 #2
You'r my man thanks a lot :)

"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
How do I set a FlagsAttribute to a run time created enum
Something like this:

eb.SetCustomAtt ribute(New

CustomAttribute Builder(GetType (FlagsAttribute ).GetConstructo r(Type.EmptyTyp e
s), New Object() {}))
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Mar 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1602
by: | last post by:
Would be nice to specify an incremenet or decremenet as an attribute in an enum so I can for example have the following... enum SomeEnum { A = 0, B, // 2 C, // 4 D /6
21
4585
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
16
82792
by: Simon | last post by:
Hi all, I think I've seen someone passing an emumeration in code before. Can anyone tell me if thats possible and why i would want to. Many thanks Kindest Regards
18
11339
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
8
8609
by: kc | last post by:
I'm trying to pull data from a database that I have no control over the structure of. There's a members table with a column for the member's sex. It just stores the sex as M or F. I'd like to create an enum to store the sex. Is there a way that I can create a method in the Enum to convert M to Male and F to Female, or does this method have to exist in another class? Thanks for any help!
2
2657
by: Stan | last post by:
Suppose there is class with enum public enum Color { Red = 20, Black = 13 } And suppose there is a method
2
2207
by: Ray Cassick \(Home\) | last post by:
I have a function that takes a value is as System.Enum and I want to be able to look at that value and determine if it is a regular enum or an enum that has a <Flag()> attribute set on it. I am trying to write a wrapper function that takes an enum and an integer value and validates if the value is actually part of the enum. Just trying to use .IsDefined will not return accurate results (as far as I can find) if the enum is a flag so if...
34
11172
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code snippet that I wrote today that gives me an instant implementation of the pattern. I could easily just always use such an implementation instead of a standard enum, so I wanted to know what you experts all thought. Is there a case for standard enums?
4
1840
by: shapper | last post by:
Hello, I have the following Enum Public Enum Mode Required Validate End Enum How can I make a variable of type Mode to hold both Required and
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8621
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.