In .net, is there a way using reflection to determine if a parameter on a method is marked with the "params" keyword?
+10
A:
Test to see whether the final ParameterInfo has ParamArrayAttribute applied to it.
Jon Skeet
2008-10-15 11:14:17
+9
A:
Check to see if a ParamArrayAttribute has been applied to the ParameterInfo object:
static void Main()
{
//use string.Format(str, args) as a test
var method = typeof (string).GetMethod(
"Format",
new[] {typeof (string), typeof (object[])});
var param = method.GetParameters()[1];
Console.WriteLine(IsParams(param));
}
static bool IsParams(ParameterInfo param)
{
return Attribute.IsDefined(param, typeof (ParamArrayAttribute));
}
Nathan Baulch
2008-10-15 11:20:29
Already said, and use Attribute.IsDefined instead.
leppie
2008-10-15 11:22:46