Guest User

Untitled

a guest
Jun 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public class Anything
  2. {
  3. public int Data { get; set;}
  4. }
  5.  
  6. public class MyGenericBase<T>
  7. {
  8. public void InstanceMethod(T data)
  9. {
  10. // do some job
  11. }
  12.  
  13. public static void StaticMethod(T data)
  14. {
  15. // do some job
  16. }
  17.  
  18. // others members...
  19. }
  20.  
  21. public sealed class UsefulController : MyGenericBase<Anything>
  22. {
  23. public void ProxyToStaticMethod()
  24. {
  25. StaticMethod(null);
  26. }
  27.  
  28. // others non derived members...
  29. }
  30.  
  31. public class Container
  32. {
  33. public UsefulController B { get; set; }
  34. }
  35.  
  36. public class Demo
  37. {
  38. public static void Test()
  39. {
  40. var c = new Container();
  41. c.B.InstanceMethod(null); // Works as expected.
  42. c.B.StaticMethod(null); // Doesn't work.
  43. // Static method call on object rather than type.
  44. // How to get the static method on the base type ?
  45. c.B.ProxyToStaticMethod(); // Works as expected.
  46. }
  47. }
  48.  
  49. public class GenericBase<T> : MyGenericBase<T>
  50. {
  51. // Create instance calls here for every base static method.
  52. }
  53.  
  54. public sealed class UsefulController : GenericBase<Anything>
  55. {
  56. // others non derived members...
  57. }
  58.  
  59. MyGenericBase<Anything>.StaticMethod( null );
  60.  
  61. UsefulController.StaticMethod(null);
  62. MyGenericBase<Anything>.StaticMethod(null);
Add Comment
Please, Sign In to add comment