在运行时创建枚举 [英] Create an enum at runtime
本文介绍了在运行时创建枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串列表,我想从他们那里建立一个
枚举...有没有办法做到这一点?
提前致谢。
-
劳伦斯押韵 Oluyede
http://loluyede.blogspot.com
解决方案
Lawrence Oluyede< ra *** @ dot.com>写道:
有没有办法做到这一点?
我想我找到了方法......我正在玩System.Reflection.Emit
-
LawrenceRhymes Oluyede
http://loluyede.blogspot.com
我能够在运行时创建一个枚举,并用我需要的值来填充它,但问题就出现了我想使用那个枚举...
....我希望班上的用户能做到这样的事情:
FooClass fc = new FooClass();
fc.FooMethod(Foos.FirstFoo);
其中Foos是枚举我在FooClass实例化时在运行时构建
和FirstFoo是它的一个领域......我怎么能这样做?
-
劳伦斯押韵 Oluyede
http://loluyede.blogspot.com
您可能希望在编译时构建枚举..如果您使用
Visual Studio,您可以使用预构建事件生成它们。否则
生成它们真的没有优势,IMO。
Richard
-
C#,.NET和复杂自适应系统:
http: //blogs.geekdojo.net/Richard
" Lawrence Oluyede" < RA *** @ dot.com>在消息中写道
新闻:87 *************** @ mobile.foo ...
我'能够在运行时创建一个枚举,并用我需要的值填充它,但当我想使用枚举时出现问题...
...我是d喜欢这个类的用户可以做这样的事情:
FooClass fc = new FooClass();
fc.FooMethod(Foos.FirstFoo);
其中Foos是我在运行时构建的枚举,当FooClass实例化为
时,FirstFoo是其中一个字段......我怎么能这样做?
-
http://loluyede.blogspot.com
I have a list of strings and i''d like to build up an
enum from them... is there a way to do that?
Thanks in advance.
--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
解决方案
Lawrence Oluyede <ra***@dot.com> writes:
is there a way to do that?
I think i''ve found the way... i''m playing with System.Reflection.Emit
--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
I''m able to create an enum at runtime and fill it with the values that i
need but the problem arises when i want to use that enumeration...
....I''d like that the user of the class could do something like this:
FooClass fc = new FooClass();
fc.FooMethod(Foos.FirstFoo);
where Foos is the enumeration I build at runtime when FooClass is instantiated
and FirstFoo is one of its fields... how can i do that?
--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
You probably want to build the enums at compile time.. if you are using
Visual Studio you could generate them with a pre-build event. Otherwise
there''s really no advantage to generating them, IMO.
Richard
--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Lawrence Oluyede" <ra***@dot.com> wrote in message
news:87***************@mobile.foo...
I''m able to create an enum at runtime and fill it with the values that i
need but the problem arises when i want to use that enumeration...
...I''d like that the user of the class could do something like this:
FooClass fc = new FooClass();
fc.FooMethod(Foos.FirstFoo);
where Foos is the enumeration I build at runtime when FooClass is instantiated and FirstFoo is one of its fields... how can i do that?
--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
这篇关于在运行时创建枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文