IMHO the only way to do that is scan for the add_<nameOfEvent> and
remove_<nameOfEvent> methods. On the IL level there's no distinction between
a delegate that was explicitly added to the class and a delegate emitted by
the C# compiler.

-- Henkk

BTW, the add_<> and remove_<> methods are just a language-ism that could
have equally well be added by hand, so the test is very empirical ...

BTW2, too bad the CSharpCodeProvider does not hand out ICodeParser
implementations ...

----- Original Message -----
From: "Łukasz Wielek" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 23, 2002 12:13 PM
Subject: [DOTNET] Reflecting events


Defining an event causes insertion of new field to the Type.

For example
public delegate char Deleg(int x, char y);
public class Class1
{
    public event Deleg Event1;
    public Deleg Event2;
    public static void Main(){}
}

The assembly tree is :
|___[CLS] Class1
| | .class public auto ansi beforefieldinit
| |___[FLD] Event1 : private class Deleg
| |___[FLD] Event2 : public class Deleg
| |___[MET] .ctor : void()
| |___[STM] Main : void()
| |___[MET] add_Event1 : void(class Deleg)
| |___[MET] remove_Event1 : void(class Deleg)
| |___[EVT] Event1 : Deleg
|
|___[CLS] Deleg
| | .class public auto ansi sealed
| | extends [mscorlib]System.MulticastDelegate
| |___[MET] .ctor : void(object,native int)
| |___[MET] BeginInvoke : class
[mscorlib]System.IAsyncResult(int32,char,class
[mscorlib]System.AsyncCallback,object)
| |___[MET] EndInvoke : char(class [mscorlib]System.IAsyncResult)
| |___[MET] Invoke : char(int32,char)


How can I distinguish normal field and a field associated with an event?
The name of the field associated with an event is not always the same as the
name of en event
(for example System.GC defines event with name "ClearCache" and has field
with name "m_cacheHandler")

Lukasz Wielek.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to