c# - How can I serialize an object that has an interface as a property? -
I have 2 interfaces and IB.
Public Interface IA (IB Interface B); Set; }} Public interface IB (IA interfaces {get; set;} zero setia (IA value);} Each interface gives context to another
I defined below I'm trying to sort classa.
[serialable] public class class A: IA {public IB interface B {get}; set;} public class () {// Interface B IB interface B = Call Out function for receiving program. GetInsanceFo RIB (); // set IB is an interface B.Secetia (this);}} [serialable] public class classby: IB {public IA interface A {Received; set;} Public Zero Setia (IA value) {this.InterfaceA = Value as ClassA;}} When I try to serialize a lot then I get an error because there are 2 properties of the interface. I want to serialize the properties. / P>
How do I see it?
I use the context in another interface I need to be able to sort the class back and forth.
Your code In your various bugs, otherwise it will work just fine.
- In the constructor for
class, you are setting a local variable IB, not the Object object of the object. In -
Classbie , you are being reverted to the object concrete, rather than leaving it alone in the form of interface type.
Here your code should look like:
Public Interface IA {IB Interface B {Receive; Set; }} Public Interface IB (IA Interfaces {Receive; Set;} Zero Setia (IA Value);} [Serialable] Public Class Class A: IA {Public IB Interface B {Received; Set;} Public Class () {// Call Out function, to obtain interface B. interface B = new ClassB (); // set beside IB set interface B.Scetia (this);}} [serialable] Public class Classbie: IB {Public IA Interface A {Receive; set ; } abstract Public Zero Setia (IA value) {this.InterfaceA = value;}} [STAThread] Fixed Zero Main () {MemoryStream ms = new MemoryStream (); BinaryFormatter bin = New BinaryFormatter (); Class A my = new class (); Bin.Serialize (MS, MAYA); Ms.osition = 0; class I myAtherA = bin.Deserialize (MS) as ClassA; Console.ReadLine ();}
Comments
Post a Comment