Comments on C # documentation

Regarding this post, I have an assembly for csc.exe / doc, so I have an XML file for the assembly that contains documentation comments.

So, I have a

  • MyAssembly.dll
  • MyAssembly.xml

Now, looking at xml, it has

<member name="M:MyAssembly.IFoo.SetTimer(System.Int32,System.Double)"> 

where IFoo is the interface defined in the assembly, and SetTimer(int, double) is the method in this interface.

I can parse this line in xml, but before going this route, there is a library that I could use to go from the MethodInfo link to get documentation comments from such xml. Sandcastle was mentioned in one of the answers, but it all seems to be related to the MSDN-style documentation generator, and I could not find examples that would allow me to do what I am trying to do.

thanks

+6
source share
1 answer

Comments are not compiled into the assembly, which means you cannot access the data in this way. Try using attributes to define additional metadata:

 public class CommentAttribute : Attribute { public CommentAttribute(string comment) { this.Comment = comment; } public string Comment { get; internal set; } } public static string GetComments(this ICustomAttributeProvider provider) { var commentAttribute = provider.GetCustomAttributes(typeof(CommentAttribute), true) .Cast<CommentAttribute>() .FirstOrDefault(); return (commentAttribute == null ? null : commentAttribute.Comment); } 

That way you can pass an instance of MethodInfo and just call GetComments() on it.

In your type add:

 [Comment("This is metadata compiled in the assembly for this type")] public class Foo { } 
+4
source

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


All Articles