Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. public class Foo<T>
  2. {
  3. protected class Private2 : Private1<Foo<T>>
  4. { }
  5.  
  6. protected class Private1<T2> where T2 : Foo<T>
  7. {
  8. public sealed class Nested
  9. {
  10. public void Test(T2 foo)
  11. {
  12. foo.Method2(this); //Nope!
  13. var nes = (Private2.Nested)this; //Nope!
  14. }
  15. }
  16. }
  17.  
  18. public void Method1()
  19. {
  20. var nested = new Private2.Nested();
  21. nested.Test(this);
  22. }
  23.  
  24. private void Method2(Private2.Nested nested)
  25. {
  26. // something code...
  27. }
  28. }
  29.  
  30. public class Bar<GoodName, OtherName, Readability, NopeMr, DontThinkSo, Suffering, Dispair>
  31. {
  32. //If only this was real...
  33. using BarT = Bar<GoodName, OtherName, Readability, NopeMr, DontThinkSo, Suffering, Dispair>;
  34.  
  35. public void Method1(BarT bar) { ... } //so good!!
  36.  
  37. //goodbye readability... see you never...
  38. public void Method2(Bar<GoodName, OtherName, Readability, NopeMr, DontThinkSo, Suffering, Dispair> whatIsThisVariable) { ... }
  39. }
  40.  
  41. public class Base {
  42. public static int Value;
  43. public class Nested { }
  44. }
  45. public class Derived:Base { }
  46.  
  47. public static void Test() {
  48. Derived.Value=10;
  49. Console.WriteLine(Base.Value);
  50. Base.Value=20;
  51. Console.WriteLine(Derived.Value);
  52. Base.Nested bn=new Derived.Nested();
  53. Derived.Nested dn=new Base.Nested();
  54. Console.WriteLine(typeof(Base.Nested).FullName);
  55. Console.WriteLine(typeof(Derived.Nested).FullName);
  56. Console.WriteLine(typeof(Base.Nested)==typeof(Derived.Nested));
  57. }
  58.  
  59. public class Foo<T>
  60. {
  61. private class Private2 : Private1
  62. { }
  63.  
  64. private class Private1
  65. {
  66. public sealed class Nested
  67. {
  68. public void Test( Foo<T> foo )
  69. {
  70. foo.Method2( this ); //Yup
  71. var nes = (Private2.Nested)this; //Yup
  72. }
  73. }
  74. }
  75.  
  76. public void Method1()
  77. {
  78. var nested = new Private2.Nested();
  79. nested.Test( this );
  80. }
  81.  
  82. private void Method2( Private2.Nested nested )
  83. {
  84. // something code...
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement