Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IA
- {
- IB InterfaceB { get; set; }
- }
- public interface IB
- {
- IA InterfaceA { get; set; }
- void SetIA(IA value);
- }
- [Serializable]
- public class ClassA : IA
- {
- public IB InterfaceB { get; set; }
- public ClassA()
- {
- // Call outside function to get Interface B
- IB interfaceB = Program.GetInsanceForIB();
- // Set IB to have A
- interfaceB.SetIA(this);
- }
- }
- [Serializable]
- public class ClassB : IB
- {
- public IA InterfaceA { get; set; }
- public void SetIA(IA value)
- {
- this.InterfaceA = value as ClassA;
- }
- }
- public interface IA
- {
- IB InterfaceB { get; set; }
- }
- public interface IB
- {
- IA InterfaceA { get; set; }
- void SetIA(IA value);
- }
- [Serializable]
- public class ClassA : IA
- {
- public IB InterfaceB { get; set; }
- public ClassA()
- {
- // Call outside function to get Interface B
- this.InterfaceB = new ClassB();
- // Set IB to have A
- InterfaceB.SetIA(this);
- }
- }
- [Serializable]
- public class ClassB : IB
- {
- public IA InterfaceA { get; set; }
- public void SetIA(IA value)
- {
- this.InterfaceA = value;
- }
- }
- [STAThread]
- static void Main()
- {
- MemoryStream ms = new MemoryStream();
- BinaryFormatter bin = new BinaryFormatter();
- ClassA myA = new ClassA();
- bin.Serialize(ms, myA);
- ms.Position = 0;
- ClassA myOtherA = bin.Deserialize(ms) as ClassA;
- Console.ReadLine();
- }
- [NonSerialized]
- [Serializable]
- public class ClassB : IB, ISerializable
- {
- public IA InterfaceA { get; set; }
- public void SetIA(IA value)
- {
- this.InterfaceA = value as ClassA;
- }
- private MyStringData(SerializationInfo si, StreamingContext ctx) {
- Type interfaceAType = System.Type.GetType(si.GetString("InterfaceAType"));
- this.InterfaceA = si.GetValue("InterfaceA", interfaceAType);
- }
- void GetObjectData(SerializationInfo info, StreamingContext ctx) {
- info.AddValue("InterfaceAType", this.InterfaceA.GetType().FullName);
- info.AddValue("InterfaceA", this.InterfaceA);
- }
- }
- [Serializable]
- public class ClassA : IA
- {
- private IB _interfaceB;
- public IB InterfaceB { get { return _interfaceB; } set { _interfaceB = value; } }
- public ClassA()
- {
- // Call outside function to get Interface B
- IB interfaceB = Program.GetInsanceForIB();
- // Set IB to have A
- interfaceB.SetIA(this);
- }
- }
- [Serializable]
- public class ClassB : IB
- {
- private IA _interfaceA;
- public IA InterfaceA { get { return _interfaceA; } set { _interfaceA = value; } }
- public void SetIA(IA value)
- {
- this.InterfaceA = value as ClassA;
- }
- }
Add Comment
Please, Sign In to add comment