Validation of attributes in the generated field for a field-like event

Given the following class definition

public class MyClass
{
    [System.ComponentModel.Browsable(true)]
    [field:NonSerialized]
    public event EventHandler MyEvent;
}

Somewhere else in my code, I would like to see the attributes of an event.

var attributes = typeof(MyClass)
                     .GetEvents()
                     .SelectMany(n => n.GetCustomAttributes(true));

But I see only BrowsableAttributein this collection of attributes.

How can I get attribute information field:NonSerialized?

+5
source share
1 answer

Syntax field:means that the attribute is bound to a field that is generated by the compiler (to support this field). You will never know the name of this field, since it is a detail of the implementation, and it is not a part EventInfo(since events do not have to be protected by a specific field - it can be proxied EventHandlerList, etc.).

, ( " ", ), ; , . BinaryFormatter ., "".

GetFields(), ; .

+2

All Articles