c# - How to insert XML comments in XML Serialization? -


I want to add some notes to the user who reads it at the top of my XML file, I'm not sure that XML How to do this with cariculiation.

I was looking at this post

  XDocument document = new XDocument (); Document.Add (New XComment ("Product XY Version 1.0.0.0")); (Var Author = Document. Cater ()) using {serializer.WriteObject (author, article); } Document.Save (Console.Out);  

But I'm not sure what's going on and how it can be added to my code. Basically I have some classes which I serialize in XML and one memory Paste in the stream.

So I'm not sure which point I should add comments to.

Thanks

Code

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.Xml.Serialization; Namespace Console Application 1 {[XmlRoot ("Course")] Public Category MyWrapper {Public MyWrapper () {TaskList = New List & amp; Work; Work & gt; (); } [XmlElement ("courseName")] public string string name {get; Set; } [XmlElement ("Background Color")] Public String Backgrounder {get; Set; } [XmlElement ("fontColor")] Public String FontColor {get; Set; } [XmlElement ("shareholders")] {get public guide sharing; Set; } [XmlElement ("Work")] Public List & Work; Work & gt; Agenda {Receive; Set; }} Public class function {[XmlAttribute ("type")] Public string type {get; Set; } [XmlElement ("taskName")] public string functionname {get; Set; } [XmlElement ("description")] public string description {get; Set; } [XmlElement ("Task Dudate")] Public Date Time Workday {Receive; Set; } [XmlElement ("weight")] Public Decimal? Weight Set; } [XmlElement ("First Dudate Notification")] Get Datatification Before Public Int; Set; } [XmlElement ("Out")] Public Decimal? Out {Go; Set; }}  

}

  using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.Xml.Serialization; Using System.IO; Namespace Console Application 1 {Class Program {Static Zero Main (string [] Args) {MyWrapper wrap = new MyWrapper (); Wrap.CourseName = "Comp 1510"; Wrap. Fontclosure = "#ffffff"; Wrap. Background color = "#ffffff"; Wrap up Sherkingky = Guide. Newguide (); Task Function = New Work () {Taskname = "First Job", Type = "Assignment", Workday Date = Date Time. Now, Details = "Description", First Dudate Notification = 30, Outoff = 50.4 M}; Wrap.TaskList.Add (function); Var stream = serialize xm (rap); } Fixed Public Memory Stream SerializeToXML (MyWrapper List) {XmlSerializer serializer = New XmlSerializer (Type (MyWrapper)); Memorystream stream = new memorystream (); Serializer.Serialize (stream, course); Return stream; }}}}  

Just as an intermediate level between memorialstream and XML Serializer Enter XMLRiator:

  Fixed Public MemoryStream SerializeToXML (MyWrapper List) {XmlSerializer serializer = New XmlSerializer (Type (MyWrapper)); Memorystream stream = new memorystream (); XmlWriter author = XmlWriter.Create (stream); Author.WriteStartDocument (); Author. White comment ("Product XY version 1.0.0.0"); Serializer.Serialize (author, course); Writer.WriteEndDocument (); Writer.flush (); Return stream; }  

You can add any XML before and after the serialized object graph (unless the result is valid XML).


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -