code_junkie

Does reflection expose if the last argument for a method was marked with 'params'?

Nov 12th, 2011
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public void MyMethod(int x, params object[] args);
  2.  
  3. public void MyMethod(int x, object[] args);
  4.  
  5. class Program
  6. {
  7. public void MethodWithParams(object param1, params int[] param2)
  8. {
  9. }
  10.  
  11. static void Main(string[] args)
  12. {
  13. var method = typeof(Program).GetMethod("MethodWithParams");
  14. var @params = method.GetParameters();
  15. foreach (var param in @params)
  16. {
  17. Console.WriteLine(param.IsDefined(typeof(ParamArrayAttribute), false));
  18. }
  19. }
  20. }
Add Comment
Please, Sign In to add comment