Hello there,
I have just found some misterious behaviour while working with System.Linq.Expressions.Expression and System.Reflection.MethodInfo.
The code is as follows:
static void Main(string[] args)
{
Expression<Func<double, double, double>> example = (x, y) => Math.Sin(x);
//Prints out "x, y":
Console.WriteLine(example.Parameters[0].Name + ", " + example.Parameters[1].Name);
//Prints out "a":
Console.WriteLine((example.Body as MethodCallExpression).Method.GetParameters()[0].Name);
}
"a"? Where did my "x" go and where did this "a" come from?
Thinking that perhaps this is an alias used at low level, I have searched for "UsedName", "VisibleName" or something along those lines, but I haven't found anything.
Unfortunately, Expression
does not feature a Parameters
property (I believe only LambdaExpression
does) which would return the "parameters in use", if any, in a given expression.
One can create a method that traverses the entire expression and collects the different parameters in use, but I was wondering if there is an easier way to do this.
Thanks a lot in advance.
Visual C# Express: 10.0.30319.1 RTMRel
.NET Framework: 4.0.30319 RTMRel