看着System.Windows.Threading.Dispatcher(由Reflector反编译)我遇到了;
[field: SecurityCritical]
public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter;
Run Code Online (Sandbox Code Playgroud)
我不承认属性声明的'field'部分,它是什么?
编辑:
这是它在参考源中的显示方式:
public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter
{
[SecurityCritical]
[UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)]
add
{
_unhandledExceptionFilter += value;
}
[SecurityCritical]
[UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)]
remove
{
_unhandledExceptionFilter -= value;
}
}
Run Code Online (Sandbox Code Playgroud)
它只是意味着它将属性应用于支持事件的委托,而不是事件本身.
就像属性语法如何简化代码一样
event MyDelegate MyEvent;
Run Code Online (Sandbox Code Playgroud)
实际上是简写
MyDelegate _BackingDelegate;
event MyDelegate MyEvent
{
add { lock (this._BackingDelegate) this._BackingDelegate += value; }
remove { lock (this._BackingDelegate) this._BackingDelegate -= value; }
}
Run Code Online (Sandbox Code Playgroud)
IIRC*,这些属性适用于_BackingDelegate和不适用MyEvent.
*注意:我不确定是否有lock声明,但我认为有.
field:称为属性目标。它允许您指定属性的目标(程序集、返回等)。
有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/b3787ac0.aspx 。