Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's this? [field:SecurityCritical] [duplicate]

Tags:

c#

Looking at System.Windows.Threading.Dispatcher (as decompiled by Reflector) I came across;

[field: SecurityCritical]
public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter;

I don't recognize the 'field' part of the attribute declaration, what is it?

Edit:

This is how it appears in the reference source:

    public event DispatcherUnhandledExceptionFilterEventHandler UnhandledExceptionFilter
    { 
        [SecurityCritical] 
        [UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)]
        add 
        {
            _unhandledExceptionFilter += value;
        }
        [SecurityCritical] 
        [UIPermissionAttribute(SecurityAction.LinkDemand,Unrestricted=true)]
        remove 
        { 
            _unhandledExceptionFilter -= value;
        } 
    }
like image 257
Grokodile Avatar asked Jun 06 '11 00:06

Grokodile


1 Answers

It just means that it's applying the attribute to the delegate that's backing the event, rather than the event itself.

Just like how property syntax is a shorthand, the code

event MyDelegate MyEvent;

is actually shorthand for

MyDelegate _BackingDelegate;

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

IIRC*, and that attributes applies to _BackingDelegate and not MyEvent.

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

like image 81
user541686 Avatar answered Sep 29 '22 06:09

user541686