人们将哪些.Net属性应用于他们的代码?

Nan*_*ook 11 .net attributes

可能重复:
C#中最有用的属性

我总是觉得我缺少可以通过简单地将属性应用于类,方法,属性等而在.Net中获得的功能.智能感知无法显示所有适当的属性,因为它们通常可以广泛应用于场景.

这是我喜欢使用的几个属性:

[DebuggerHidden] - 将此放置在方法上可防止Visual Studio调试器插入代码.如果您有一个不断触发和中断调试的事件,这将非常有用.

[EditorBrowsable(EditorBrowsableState.Never)] - 隐藏intellisense中的方法.我不经常使用它,但它在构建可重用组件时很方便,并且您想隐藏一些测试或调试方法.

我想看看其他人在使用什么,以及人们有什么提示.

Rub*_*ias 4

我刚刚找到这个资源:

 

// The DebuggerDisplayAttribute can be a sweet shortcut to avoid expanding
// the object to get to the value of a given property when debugging. 
[DebuggerDisplay("ProductName = {ProductName},ProductSKU= {ProductSKU}")] 
public class Product 
{ 
    public string ProductName { get; set; } 
    public string ProductSKU { get; set; } 
}

// This attribute is great to skip through methods or properties 
// that only have getters and setters defined.
[DebuggerStepThrough()] 
public virtual int AddressId 
{ 
    get { return _AddressId;}     
    set 
    { 
        _AddressId = value;   
        OnPropertyChanged("AddressId"); 
    } 
}

// The method below is marked with the ObsoleteAttribute. 
// Any code that attempts to call this method will get a warning.
[Obsolete("Do not call this method.")]
private static void SomeDeprecatedMethod() { }

// similar to using a combination of the DebuggerHidden attribute, which hides
// the code from the debugger, and the DebuggerStepThrough attribute, which tells
// the debugger to step through, rather than into, the code it is applied to.
[DebuggerNonUserCode()]
private static void SomeInternalCode() { }
Run Code Online (Sandbox Code Playgroud)