I got an internal method where one of the input parameter is an internal Enum. How do I get a enum value and pass it to the method?
Example:
internal enum MyEnum
{
One,
Two,
Three
}
internal int InternalTest(string test, MyEnum enumTest)
{
return test.Length;
}
And then obtained by something like this:
MethodInfo addInternal = typeof(Class1).GetMethod("InternalTest", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(string), typeof(?????) }, null);
Thanks!
Ivar
Try
typeof(Class1).GetNestedTypes(). It should return a list all types that nested into Class1 – like MyEnum is. So look through the list of nested types, find the MyEnum type and pass it to GetMethod.GetNestedTypes documentation on MSDN: http://msdn.microsoft.com/en-us/library/system.type.getnestedtypes(v=vs.100).aspx
There is also a
GetNestedType()method that accepts a type name and some BindingFlags which allows you to search for specific nested type by name.To get a value of the enum using reflection, use this: