Assuming I have the following structure:
public enum RemoteButtons
{
Play,
Pause,
Stop
}
public class RemoteControl
{
public bool Push(RemoteButtons button)
{
Console.WriteLine(button.ToString());
return true;
}
}
Then I can use reflection to get at the values like so:
Assembly asm = Assembly.GetExecutingAssembly();
Type remoteControlType = asm.GetType("WindowsFormsApplication1.RemoteControl");
object remote = Activator.CreateInstance(remoteControlType);
var methodInfo = remoteControlType.GetMethod("Push");
var remoteButtons = methodInfo.GetParameters()[0];
// .Net 4.0
// var enumVals = remoteButtons.ParameterType.GetEnumValues();
// .Net 3.5
var enumVals = Enum.GetValues(remoteButtons.ParameterType);
methodInfo.Invoke(remote, new object[] { enumVals.GetValue(0) }); //Play
methodInfo.Invoke(remote, new object[] { enumVals.GetValue(1) }); //Pause
methodInfo.Invoke(remote, new object[] { enumVals.GetValue(2) }); //Stop
I am getting the parameter type from the method and then getting the enum values from that type.