XML serialization

Is there a way to serialize a CodeCompileUnit object as XML.

The problem is that:

XmlSerializer xml = new XmlSerializer( typeof(CodeCompileUnit) );

throws the following exception:

"It is not possible to serialize a member of System.CodeDom.CodeObject.UserData of type System.Collections.IDictionary because it implements IDictionary."

+3
source share
3 answers

XmlSerializer has problems with IDictionary. Now it is deprecated in favor of a DataContractSerializer that can serialize an instance of CodeCompileUnit:

var serializer = new DataContractSerializer(typeof(CodeCompileUnit));
serializer.WriteObject(Console.OpenStandardOutput(), new CodeCompileUnit());
+3
source

XML-: ( ). , IXmlSerializable (, , ), UserData...

+1

It may be a long shot, but what about serializing the code that it generates and then renames the code from the generated code.

This project allows you to switch from code to code and vice versa.

http://www.codeproject.com/KB/cs/codedom_assistant.aspx

+1
source

Source: https://habr.com/ru/post/1709238/


All Articles