4

I have a serializable class that I'd like to serialize with its data (of course) and also with its XmlDoc comments. Does anyone know of an existing library that does that job, or at least part of it?

Reading the XmlDoc of a C# code the way Intellisense does it is a good starting point.

Because examples speak better than theory, I'd like to have the following (C#) code

public class ApplicationOptions : ISerializable
{
    ///<summary>This parameter describes the X property</summary>
    public int WindowPositionX;

    ///<summary>This comment is the same as in the XML-serialized form</summary>
    public int WindowPositionY;
}

Mapped to the following serialized XML form

<!--This parameter describes the X property-->
<parameter name="WindowPositionX" Value=12 />

<!--This comment is the same as in the XML-serialized form-->
<parameter name="WindowPositionY" Value=13 />
PPC
  • 1,734
  • 1
  • 21
  • 41

1 Answers1

2

I don't know any library that does this, you can write your custom serializer for the class and add the comments using the custom serializer like done here: How to write a comment to an XML file when using the XmlSerializer?

But you will have to read the yourlibraryfile.xml companion file to get the comments, comments are not compiled with the application.

Community
  • 1
  • 1
jmservera
  • 6,454
  • 2
  • 32
  • 45
  • I'm not very happy with parsing myself the DOM of the MS XmlDoc files (and look for them in my project space). Still hoping to find a library to do the dirty job for me.. – PPC Oct 29 '12 at 21:20
  • 1
    No need to parse, you can query with Linq to XML for finding the name of class and property http://msdn.microsoft.com/en-us/library/bb387061.aspx – jmservera Oct 29 '12 at 22:39