ehsan_d18
ehsan_d18

Reputation: 281

Add a description for a property

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;
    }
}

Upvotes: 16

Views: 31236

Answers (4)

Ajay2707
Ajay2707

Reputation: 5798

In Asp.net Core c# coding, it is different. Its work of all asp.net core version.

 [Display(Name = "Employee Name")]  
 public string EmployeeName { get; set; }  

Upvotes: 1

Ali
Ali

Reputation: 3469

(A bit late but maybe helpful to someone)

Another option that you can use is:

[Browsable(true)]

If the Browsable is true, you can see the property in Property Window and when its false, no one could not change it via Property Window in designer. See more information about that.

Upvotes: 1

Dan Abramov
Dan Abramov

Reputation: 268225

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.

Upvotes: 16

dtb
dtb

Reputation: 217263

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; }

Upvotes: 28

Related Questions