Are there attributes in C# for affecting how Intellisense displays class members?

感情迁移 提交于 2019-12-01 06:04:40

问题


Are there any C# attributes that I can apply to class members, to change the way they appear in the Intellisense listings? This popped into my head when I was building a class with many static constants, and I (briefly!) wanted it to look like an enumeration in Intellisense.

Yes, that's silly.

But it got me thinking - is there any way some crazy programmer can make a class members appear differently in the Intellisense? Make fields look like properties, etc?

For instance, there's the Obsolete attribute:

[Obsolete("Stop using this. Really. It's old.")]
public int VariableThatIsReallyOld;

Which prefixes the word [obsolete] to the description of VariableThatIsReallyOld.


回答1:


There's the DebuggerDisplay attribute described here.




回答2:


I tend to think that manipulating the comments is a much better proposition.

///<summary>
/// Bomb!
///</summary>
///<example></example><value></value><![CDATA[]]><param name="ss"></param><exception   cref="ss"></exception><remarks></remarks>
///<returns></returns> 

If you dig into the options available in the comment structure(which the intellisense and compiler understands) like <example>,<include>,<see>,<seealso>,<exception> etc, you can pretty get all the functionality sans performance dip introduced by the attribute.




回答3:


Turns out there also some other attributes at Custom intellisense for server controls? (But the search continues!)

[EditorBrowsable(EditorBrowsableState.Never)]


来源:https://stackoverflow.com/questions/684747/are-there-attributes-in-c-sharp-for-affecting-how-intellisense-displays-class-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!