What is it? [Field: SecurityCritical]

Looking at System.Windows.Threading.Dispatcher (as a Reflector decompiled), I came across:

[field: SecurityCritical] public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter; 

I do not recognize the "field" of the attribute declaration part, what is it?

Edit:

Here's how it appears in the original source:

  public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter { [SecurityCritical] [UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)] add { _unhandledExceptionFilter += value; } [SecurityCritical] [UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)] remove { _unhandledExceptionFilter -= value; } } 
+6
source share
4 answers

field: called the target attribute. It allows you to specify the target (assembly, return, etc.) for the attribute.

See http://msdn.microsoft.com/en-us/library/b3787ac0.aspx for more details.

+3
source

It just means that it applies the attribute to the delegate that supports the event, not the event itself.

Just as property syntax is shorthand, code

 event MyDelegate MyEvent; 

is actually abbreviated for

 MyDelegate _BackingDelegate; event MyDelegate MyEvent { add { lock (this._BackingDelegate) this._BackingDelegate += value; } remove { lock (this._BackingDelegate) this._BackingDelegate -= value; } } 

IIRC *, and these attributes apply to _BackingDelegate , not MyEvent .

* Note. I'm not sure if there is a lock statement or not, but I think it does.

+6
source

The syntax for attribute purposes is as follows:

 [target : attribute-list] 

Where target is one of the following: assembly, field, event, method, module, parameter, property, return, type.

Here you can find a complete list of possible goals: Non-radiating attribute goals

SecurityCritical cannot be applied to an event. But it can be applied to the backup EventHanlder field.

+3
source

When you declare an attribute for an event, you can apply the attribute either to the event itself or to the field in which the event delegate is passed by the generated add and remove methods. The field means that the attribute is applied to the field.

See Non-Radiating Target Attributes on MSDN, as well as this question .

+1
source

Source: https://habr.com/ru/post/889837/


All Articles