views:

85

answers:

4

How do I write a class so that property and method descriptions are visible to people referencing the dll in other projects?

    [Description("My age in years attribute")]
    public int Age
    {
        get { return 0; }
        set { }
    }

doesn't work, neither does

    /// <summary>
    /// My age in years attribute
    /// </summary>
    public int Age
    {
        get { return 0; }
        set { }
    }
+1  A: 

The description provided in DescriptionAttribute is visible in Property Grid for sure and it has nothing to do with code editor.

For XML comments to be available, you have to generate an XML documentation file and ship it with your assembly.

Anton Gogolev
+12  A: 

In Visual Studio:

Project -> Properties -> Build -> Check "XML Documentation File".

For further details, see XML Comments Let You Build Documentation Directly From Your Visual Studio .NET Source Files.

Jason
Does this mean I need to distribute the XML with the DLL and reference them both? Is there any way I can just have all the information in the DLL?
James
No, the XML comments are not part of any metadata in the assembly.
Jason
How do I make them part of the metadata?
James
@James: You could embed the output XML file as a resource in the DLL. But why would you want to do this? There is already a perfectly standard way of shipping the XML comments with the DLL. Visual Studio integrates nicely with the XML files that are output by the process described above.
Jason
Thanks Jason. I'm working on an in house project so my methods are limited. Restricting things to a standalone DLL with embedded XML makes things more manageable
James
@James: Okay; fair enough. Glad that I could help.
Jason
+1  A: 

Did you build the XML documentation file for your second case?

Project properties -> Build -> [Output] XML Documentation file

tanascius
+1  A: 

The second should work (summary), be sure to select in the project Properties (Build -> Output ) XML Documentation File.

Alex LE