我想通过根的字符串名称来引用枚举。请注意,我希望引用枚举,而不是枚举成员。
stackoverflow 上有很多帖子描述了如何通过其名称来引用枚举成员(例如 ,如何根据其名称检索枚举成员),但我没有找到任何关于如何通过其根名称来引用枚举的信息。
进一步澄清;
Enum MyEnumA : Quiet : Noisy : End enum
Enum MyEnumB : Big : Small : Gigantic : End enum
Sub Foo(strAction as string)
' Depending on value of strAction, i want to create a list of either MyEnumA or MyEnumB members
' I know i can't do the following, it's just to make clear the direction i'm wanting to go -
Dim lstMembers As New List(Of CType(strAction,[Enum]))
'....
end function
按照下面的好建议,我已经尝试过了;
Dim enumType As Type = System.Type.GetType("ExcelInterface.clsBTAnalyseRslts+" & "strAction")
Dim lstFldIndx As New List(Of enumtype) 'Fails to compile this line as doesn't recognize enumtype as defined
谢谢!