Guest User

Untitled

a guest
Jun 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. public interface IA
  2. {
  3. IB InterfaceB { get; set; }
  4. }
  5.  
  6. public interface IB
  7. {
  8. IA InterfaceA { get; set; }
  9.  
  10. void SetIA(IA value);
  11. }
  12.  
  13. [Serializable]
  14. public class ClassA : IA
  15. {
  16. public IB InterfaceB { get; set; }
  17.  
  18. public ClassA()
  19. {
  20. // Call outside function to get Interface B
  21. IB interfaceB = Program.GetInsanceForIB();
  22.  
  23. // Set IB to have A
  24. interfaceB.SetIA(this);
  25. }
  26. }
  27.  
  28. [Serializable]
  29. public class ClassB : IB
  30. {
  31. public IA InterfaceA { get; set; }
  32.  
  33. public void SetIA(IA value)
  34. {
  35. this.InterfaceA = value as ClassA;
  36. }
  37. }
  38.  
  39. public interface IA
  40. {
  41. IB InterfaceB { get; set; }
  42. }
  43.  
  44. public interface IB
  45. {
  46. IA InterfaceA { get; set; }
  47. void SetIA(IA value);
  48. }
  49.  
  50. [Serializable]
  51. public class ClassA : IA
  52. {
  53. public IB InterfaceB { get; set; }
  54.  
  55. public ClassA()
  56. {
  57. // Call outside function to get Interface B
  58. this.InterfaceB = new ClassB();
  59.  
  60. // Set IB to have A
  61. InterfaceB.SetIA(this);
  62. }
  63. }
  64.  
  65. [Serializable]
  66. public class ClassB : IB
  67. {
  68. public IA InterfaceA { get; set; }
  69.  
  70. public void SetIA(IA value)
  71. {
  72. this.InterfaceA = value;
  73. }
  74. }
  75.  
  76. [STAThread]
  77. static void Main()
  78. {
  79. MemoryStream ms = new MemoryStream();
  80. BinaryFormatter bin = new BinaryFormatter();
  81.  
  82. ClassA myA = new ClassA();
  83.  
  84. bin.Serialize(ms, myA);
  85.  
  86. ms.Position = 0;
  87.  
  88. ClassA myOtherA = bin.Deserialize(ms) as ClassA;
  89.  
  90.  
  91. Console.ReadLine();
  92. }
  93.  
  94. [NonSerialized]
  95.  
  96. [Serializable]
  97. public class ClassB : IB, ISerializable
  98. {
  99. public IA InterfaceA { get; set; }
  100.  
  101. public void SetIA(IA value)
  102. {
  103. this.InterfaceA = value as ClassA;
  104. }
  105.  
  106. private MyStringData(SerializationInfo si, StreamingContext ctx) {
  107. Type interfaceAType = System.Type.GetType(si.GetString("InterfaceAType"));
  108. this.InterfaceA = si.GetValue("InterfaceA", interfaceAType);
  109. }
  110.  
  111. void GetObjectData(SerializationInfo info, StreamingContext ctx) {
  112. info.AddValue("InterfaceAType", this.InterfaceA.GetType().FullName);
  113. info.AddValue("InterfaceA", this.InterfaceA);
  114. }
  115. }
  116.  
  117. [Serializable]
  118. public class ClassA : IA
  119. {
  120. private IB _interfaceB;
  121. public IB InterfaceB { get { return _interfaceB; } set { _interfaceB = value; } }
  122.  
  123. public ClassA()
  124. {
  125. // Call outside function to get Interface B
  126. IB interfaceB = Program.GetInsanceForIB();
  127.  
  128. // Set IB to have A
  129. interfaceB.SetIA(this);
  130. }
  131. }
  132.  
  133. [Serializable]
  134. public class ClassB : IB
  135. {
  136. private IA _interfaceA;
  137. public IA InterfaceA { get { return _interfaceA; } set { _interfaceA = value; } }
  138.  
  139. public void SetIA(IA value)
  140. {
  141. this.InterfaceA = value as ClassA;
  142. }
  143. }
Add Comment
Please, Sign In to add comment