xml serialization - Tweak output from XmlSerializer in C# -


I am thinking that there is a way to change the XmlSerializer in C # that is to convert it to a property of an object Does output to. For example, if I have something like this:

  public square michael {public string prop1 {get}} public UIT prop 2 {get;} public MyClass2 class2 {get;} public MyClass3 class3 {Get; }} Public class MyClass2 {public string prop3 {get;}} public class MyClass3 {// I want to serialize a lot of properties}   

Now in my code, I have something like this:

  Private Zero Serializestaff (list & lt; MyClass & gt; list, string path) {XmlSerializer serialize = new XML CERTILIZER (typef (list & lt; MyClass & Gt;); Text writer author = new streamer (route); Serialize.Serialize (author, list); Writer.Close (); }   

What do I want to do is to work in serialization as normal, but with some other stuff with prop3 has been replaced Example:

  & lt; MyClass & gt; & Lt; Prop1 & gt; Whatever & lt; / Prop1 & gt; & Lt; Prop2 & gt; 345 & lt; / Prop2 & gt; & Lt; Class2 & gt; & Lt; SomethingNotProp3 & gt; Whatever & lt; / SomethingNotProp3 & gt; & Lt; SomethingElseNotProp3 & gt; Whatever & lt; / SomethingElseNotProp3 & gt; & Lt; / Class2 & gt; & Lt; Class3 & gt; ... & lt; / Class3 & gt; & Lt; / MyClass & gt;   

Is there a way to customize XmlSerializer, so I do not have to write the entire XML file manually, or there is no way to do this?

EDIT: I am pretty sure that there may be something in the solution to implement the ISerializable method of GetObjectData ; However, I am not sure how to implement it. I tried to apply MySQL2 to iaselizable and apply GetObjectData , but nothing changed prop3 still had the output in the XML file. Use features in

To influence the way to serialize the example.

If you require specialized codecs for MyClass3 , then you can not handle the attributes, then apply that will give you full control over the serialization process (you can enter content / property You can also decide on an example-by-example basis to sort them).

Depending on the comments, it appears that you IXmlSerializable , as you want to change the name of the property and the value; Attributes will let you rename the property / element / attribute, but will not allow you to change the value (and I think that you do not want to corrupt your representation and want to add an additional property / value for this purpose ).

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -