9

Is it possible to add XML comments for set and get accessors which will be visible in Object Browser (VS 2010)?

/// <summary>
/// Something about property.
/// </summary>

public bool IsSomething
{
    // get description

    get
    {
        return isSomething;
    }

    // set description

    set
    {
        // do some work
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
apocalypse
  • 5,764
  • 9
  • 47
  • 95
  • If you'd really like to add comments for get and set independently, you could always implement the getter and setter methods yourself, then put your XML comments on the getter and setter methods. – Isaac Overacker May 27 '12 at 01:25
  • 1
    It would be meaningless most of the time if you could. Properties should not be responsible for complex logic. If you want to apply some complex logic, forget about properties and write a method and add your comments. Since you don't want to do a lot of logic inside your properties you don't need to comment them. – Mert Akcakaya May 27 '12 at 01:38
  • I use properties for logic which use very few cpu resources. For complex logic (more cpu usage) I use methods. But I just ask... some properties can have logic like constraints set value to 0..100 for byte etc. – apocalypse May 27 '12 at 02:12

2 Answers2

10

No, you cannot set these comments directly on the accessors. The comments on the property, however, can be quite comprehensive, you will get IntelliSense suggestions when you start to type them. If you have extended comments, you might want to put the extra stuff in the remarks section of the comment:

/// <summary>
///   Something about the property.
/// </summary>
/// <remarks>
/// Some extra remarks that won't show up in the property's IntelliSense later.
/// </remarks>
Pang
  • 9,564
  • 146
  • 81
  • 122
slugster
  • 49,403
  • 14
  • 95
  • 145
3

Don't think so, at least not in that location. I would just add the info inside of other existing tags, like so:

/// <summary>
/// Gets or sets the x.
/// </summary>
/// <value>
/// The x.
/// </value>
/// <returns> this saves the world</returns>
/// <remarks> when you set this the world ends</remarks>
Pang
  • 9,564
  • 146
  • 81
  • 122
madmik3
  • 6,975
  • 3
  • 38
  • 60