Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a description for a property

Tags:

c#

How do I add a text description for my property?

alt text

My code :

private bool _SpaceKey;

public bool SpaceKey
{
    get
    {
        return _SpaceKey;
    }
    set
    {
        _SpaceKey = value;
    }
}
like image 271
ehsan_d18 Avatar asked Sep 30 '10 16:09

ehsan_d18


2 Answers

Have a look at the Description Attribute:

[Description("This is the description for SpaceKey")]
public bool SpaceKey { get; set; }

You can additionally use the Category Attribute to specify the category of the property:

[Category("Misc")]
[Description("This is the description for SpaceKey")]
public bool SpaceKey { get; set; }
like image 78
dtb Avatar answered Oct 05 '22 23:10

dtb


If you want to see the description in the Visual Studio designer (or any other compatible IDE), you'll need to use design-time attributes for components which are defined in System.ComponentModel namespace.

[Description("This is the description of Space Key.")]
public bool SpaceKey { get; set; }

Before doing so, consider learning how to write a good description from descriptions in class library (though they're not always helpful, either). It's good to follow the existing style.

If you want to see hints in code, like tooltips when selecting a member with IntelliSense, you need to also use XML comments for documentation:

/// <summary>
/// Gets or sets space key (that would probably make a bad summary).
/// </summary>
public bool SpaceKey { get; set; }

That's it.

like image 43
Dan Abramov Avatar answered Oct 05 '22 22:10

Dan Abramov