Is it possible to obtain class summary at runtime in C#? I would like to obtain class summary through reflection and then write it to console. By class summary I mean summary comments before class definition, something like this:
/// <summary>
/// some description
/// </summary>
class SomeClass
{
}
I don't know if these comments are available after compiling the code, but if they are maybe there is a way to obtain them in code.
Thanks in advance for help.
Reflection provides objects that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object. You can then invoke the type's methods or access its fields and properties.
Provides access to custom attribute data for assemblies, modules, types, members and parameters that are loaded into the reflection-only context. Contains static methods for retrieving custom attributes.
Reflection namespace. The System. Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application.
The use of XML doc comments requires delimiters that indicate where a documentation comment begins and ends. You use the following delimiters with the XML documentation tags: /// Single-line delimiter: The documentation examples and C# project templates use this form.
I once messed with this a while back, and used this guys solution. Worked pretty good:
http://jimblackler.net/blog/?p=49
I maintain the Jolt.NET project on CodePlex and have implemented a feature that performs this very task. Please refer to the Jolt library for more information.
In essence, the library allows you to programatically locate and query an XML doc comments file for an assembly using the metadata types in System.Reflection
(i.e. MethodInfo
, PropertyInfo
, etc...).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With