|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Access private enumeration using reflectionI would highly appreciate some help with how to access an enumeration declared as private in a class from the outside of the class. This is a simplified example of the situation: Const CONSTANT_1 As Integer = 4 Const CONSTANT_2 As Integer = 7 Public Class aClass Private Enum myEnum first = CONSTANT_1 second = CONSTANT_2 third End Enum End Class Module Test Sub Main() Dim myClassObject As aClass = New aClass Dim classType As Type = myClassObject.getType() Dim bf As BindingFlags = BindingFlags.NonPublic Or BindingFlags.Static Dim m As MemberInfo = classType.GetMember("myEnum", bf)(0) System.Enum.Parse(m.getType(), "third") End Sub End Module I think my problem is how to convert the MemberInfo into a Enum object. My goal is to acces the "third" constant in myEnum. The type returned by MemberInfo is "RuntimeType", which Enum.parse does not allow. Is there a way to convert my Type to an Enum? Is my approach all wrong? Thanks! Fredrik,
>System.Enum.Parse(m.getType(), "third") Change this to System.Enum.Parse(CType(m, Type), "third") and it should be ok. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Timespan perplexing, please help with brain freeze.
Reg expression How to declare char string pointer in VB? DataGridView - Property DataPropertyName Threading 101 Can the read() function in VB.NET start reading from somewhere else than 0 Frustrations with RTF format. KeyDown for non Active windows? Playing card suits, vb.net? XML Logging Write one record |
|||||||||||||||||||||||