Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public abstract class BaseFoo
  2. {
  3. public BaseFoo()
  4. {
  5. FooMethod();
  6. }
  7.  
  8. public abstract void FooMethod();
  9. }
  10.  
  11. public class Foo : BaseFoo
  12. {
  13. private Stream _stream;
  14.  
  15. public Foo(Stream stream)
  16. {
  17. _stream = stream;
  18. }
  19.  
  20. public override void FooMethod()
  21. {
  22. //do anything with the stream
  23. _stream.Read(...);
  24.  
  25. //--> _stream = null
  26. }
  27. }
  28.  
  29. public Foo(Stream stream)
  30. {
  31. _stream = stream;
  32.  
  33. base();
  34. }
  35.  
  36. public abstract class BaseFoo
  37. {
  38. public BaseFoo(bool testToDoSomething)
  39. {
  40. FooMethod();
  41. }
  42.  
  43. public abstract void FooMethod();
  44. }
  45.  
  46. public abstract class BaseFoo
  47. {
  48. private Action toRunOnConstruct;
  49. public BaseFoo(Action toRunOnConstruct)
  50. {
  51. this.toRunOnConstruct = toRunOnConstruct;
  52. toRunOnConstruct.Invoke();
  53. }
  54. }
  55.  
  56. public class Foo : BaseFoo
  57. {
  58. private Stream _stream;
  59.  
  60. public Foo(Stream stream) : base(()=> SomethingToDoWithTheStream(stream))
  61. {
  62. _stream = stream;
  63. }
  64.  
  65. public static void SomethingToDoWithTheStream(Stream stream)
  66. {
  67. //do anything with the stream
  68. stream.Read(...);
  69.  
  70. //--> _stream = null
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement