How can I get the values of parms (in a loop using reflection). In previous question, someone showed me how to loop through the parms using reflection.
static void Main(string[] args)
{
ManyParms("a","b","c",10,20,true,"end");
Console.ReadLine();
}
static void ManyParms(string a, string b, string c, int d, short e, bool f, string g)
{
var parameters = MethodBase.GetCurrentMethod().GetParameters();
foreach (ParameterInfo parameter in parameters)
{
string parmName = parameter.Name;
Console.WriteLine(parmName);
//Following idea required an object first
//Type t = this.GetType();
//t.GetField(parmName).GetValue(theObject));
}
}
If you must know why I want to do this, please see here: http://stackoverflow.com/questions/1862433/net-reflection-of-all-method-parameters
Thanks,
Neal Walters
Thanks all - it seems like in Python, PERL, PHP this would be easy.
Even though it may not be reflection, if I use reflection to get the field name, seems like there would be an easy dynamic way to get the value based on the name.
I haven't tried AOP (Aspect Oriented Programming) the solutions yet.
This is one of those things that if I can't do it in an hour or two, I probably won't do it.