积极答复者
Silverlight中的Enum

问题
答案
-
你好
在SILVERLIGHT 中的ENUM 確是決小了 GETNAMES/GETVALUES 這2個方法
In the absence of the Enum.GetNames and Enum.GetValues methods, which are not supported in Silverlight, you can use reflection to iterate the public static fields of an enumeration type. Each field is represented by a FieldInfo object. Its Name property returns the name of the enumeration member. Its GetValue property returns the underlying value of the enumeration member.
This gives you a choice of how you want to create enumeration instances when you iterate the enumeration type's public static fields. You can retrieve their names and pass them to the Enum.Parse method. You can retrieve their values and pass them to the Enum.ToObject method. Or you can retrieve their values and cast them (in C#) or convert them (in Visual Basic) to enumeration values.
The following is some C# code that enumerates the fields of the DayOfWeek enumeration and instantiates DayOfWeek values in these three ways: ....詳情可以參考以下URL
http://msdn.microsoft.com/en-us/library/dd229102(v=vs.95).aspx
Please correct me if my concept is wrong
Chi- 已标记为答案 天使坠Moderator 2011年5月19日 2:31
全部回复
-
你好
在SILVERLIGHT 中的ENUM 確是決小了 GETNAMES/GETVALUES 這2個方法
In the absence of the Enum.GetNames and Enum.GetValues methods, which are not supported in Silverlight, you can use reflection to iterate the public static fields of an enumeration type. Each field is represented by a FieldInfo object. Its Name property returns the name of the enumeration member. Its GetValue property returns the underlying value of the enumeration member.
This gives you a choice of how you want to create enumeration instances when you iterate the enumeration type's public static fields. You can retrieve their names and pass them to the Enum.Parse method. You can retrieve their values and pass them to the Enum.ToObject method. Or you can retrieve their values and cast them (in C#) or convert them (in Visual Basic) to enumeration values.
The following is some C# code that enumerates the fields of the DayOfWeek enumeration and instantiates DayOfWeek values in these three ways: ....詳情可以參考以下URL
http://msdn.microsoft.com/en-us/library/dd229102(v=vs.95).aspx
Please correct me if my concept is wrong
Chi- 已标记为答案 天使坠Moderator 2011年5月19日 2:31
-
你好,
“然后我去Silverlight的类库中确认下,这几个方法也存在”
请问你是怎么确认的?
我和天使坠(陈曦)一样,确实没有发现有GetNames,GetValues方法。
请参阅以下文档,下面显示的是Emun所具有的方法:
http://msdn.microsoft.com/zh-cn/library/system.enum_methods%28v=VS.95%29.aspx
你可以通过查看Emun 的 Metadata,也会发现是和文档一样的 (选中 Enum 类名,按下F2 可以查看)
Daoping Liu - MSFT