473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Access private enumeration using reflection

Hi!

I 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!

Apr 7 '06 #1
1 2108
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.
Apr 9 '06 #2

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

Similar topics

3
by: J E E | last post by:
Hi! Is it possible to access fields in a derived class using reflection? Code below works fine when I access it as a private member in the Page class, but not when accessing base class member...
17
by: Pam Ammond | last post by:
I need to use Microsoft Access Automation within a Visual Studio 2003 program written in C# for Windows Forms. When a button is clicked in my VS.NET program, I want it to run a Microsoft Access...
2
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
3
by: Brett Kelly | last post by:
Hello all, I'm in a situation where I need to retrieve a member from the System.Data.SqlDbType enumeration knowing only the type name. At this point, I'm just trying to get reflection to...
10
by: Abelardo Vacca | last post by:
Hi, The title sums up the question pretty much. I would like to access all private members of a class including the private members of its base classes.( I already have the ReflectionPermission )...
1
by: Carl Gilbert | last post by:
Hi I am trying to iterate through an enumeration type using reflection to show the different options available. So far I have got the app to show the type (Int, Boolean, enum, etc) but need to...
8
by: Joel Reinford | last post by:
I would like to build a class that has properties which can be accessed by string names or index numbers in the form of MyClass.Item("LastName"). The string names or item index values would be...
7
by: Nathan | last post by:
I'd like to use an enumeration as a datasource for a drop-down box. Is there a way to do this?
1
by: lactaseman | last post by:
While I know this is not the correct venue... I realize this is of little to no importance to most out there... however, if I had found this in my initial searches, I would have used this. So, as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.