c# - Derived Class Deserialization -
There is a problem with deserialization with my logic simulation program. These are my element classes: < Pre> And here are the sections responsible for sections: Signal data is not important here. So, I will not write it (to keep this question clear) Even until someone says that it is not necessary. CircuitData is very important: The strings are not important anymore. Now, I have written some of the serialization: This works as I wanted, it produces the XML document: But I have a problem with my classification. Here's the code: Now, it deserializes my I have a suggestion for you, Gives the object to this method, you can make your public class AndGateData: two inputgate data {} public class two inputgate data: gate data {public two inputgate data () {Input2 = new InputData (); Input 1 = new input data (); } Public InputData Input1 {get; Set; } Public Input Data Input2 {get; Set; }} Public class gatetta: elementadata {public gate data () {outputdata = new output data (); } {Receive public output data output data; Set; }} Public Class Elementadata {public int delay {get; Set; } Get Public Guide ID { Set; }}
Public category inputdata: socketdata {} public class socketdata {public guide id {get; Set; } Receive Public Signal Data Signals { Set; }}
[XmlRoot ("circuits")] public class circuits [XmlElement (typeg (orgatedata)) [XmlElement (typef (orgatedata)) ] Public List & LT; Elementandata & gt; Element = new list & lt; ElementData & gt; (); Public listing & lt; WireData & gt; Wire = new list & lt; WireData & gt; (); Public Zero Adelament (Elementadata Element) {elements.Add (element); } Public Zero AddWire (WireData Wire) {Wired. Add (wire); }}
public class circuits detergent {write public static void (object obj , String filename) {var xmlFormat = new XmlSerializer (Typef (CircuitData)); (Stream fstream = new filestream (using filename, file mode.creative, fileexe.Weight, fileshore.NON)) {xmlFormat.Serialize (fStream, obj); } Console. WrightLine ("Saved in Circuit XML Format."); }}
& Lt; / Input 1 & gt; - & lt; Input 2 & gt; & Lt; Eid & gt; D2cad8f8-8528-4db3-9534-9baadb6a2a14 & lt; / Id & gt; & Lt; Signal data xsi: type = "signaldataoff" /> & Lt; / Input 2 & gt; & Lt; / AndGateData> & Lt; Stars / & gt; & Lt; / Circuits & gt;
Read public static circuits () {var reader = New XmlSerializer (Typef (CircuitData)); Streamer file = new streamer ("circuit.exml"); Var returnCircuitData = new circuit data (); RefundCard data = (CircuitData) Reader. Diaryialize (file); Return returnscrudeddata; }
Circuit.xml for this object, but in this object, only
Id and
Delay , does not contain
Input1 ,
Input2 or
output . Therefore, it is treated like the
element , such as
AndGate not. I tried to solve it for one day but it seems that there is no such problem.
type Create and
objectToSerialize.GetType () :
Create serializer by using the public Write zero zero & lt; T & gt; (T ObjectusTorialize, string filename) {var xmlSerializer = New XML SerialIizer (objectToSerialize.GetType ()); ...}
read the common method like this:
Public stable T & Lt; T & gt; (String filename) {var serializer = new XML serializer (typef (t)); (Using the streamrider file = new streamrider (filename)) {Return (T) Serializer. Diaryialize (file); Besides, you may want to read about it:
Comments
Post a Comment