fork download
  1. using System;
  2.  
  3. namespace ConsoleApplication1
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Sample3 s3 = new Sample3();
  10. s3.write(new Sample1());
  11. s3.write(new Sample2());
  12. s3.write(new Sample0());
  13. }
  14. }
  15.  
  16. class Sample0
  17. {
  18.  
  19. }
  20. class Sample1
  21. {
  22. public void write()
  23. {
  24. Console.WriteLine("1");
  25. }
  26. }
  27.  
  28. class Sample2
  29. {
  30. public void write()
  31. {
  32. Console.WriteLine("2");
  33. }
  34. }
  35.  
  36. class Sample3
  37. {
  38. public void write(Object x)
  39. {
  40. if (x.GetType().GetMethod("write") == null)
  41. {
  42. Console.WriteLine("Invalid argument");
  43. }
  44. else
  45. {
  46. x.GetType().InvokeMember("write", System.Reflection.BindingFlags.InvokeMethod, null, Activator.CreateInstance(x.GetType(), true), null);
  47. }
  48. }
  49. }
  50. }
Success #stdin #stdout 0.04s 33896KB
stdin
Standard input is empty
stdout
1
2
Invalid argument