Hi all,
I have a reflection-problem I'm totally stuck with. Maybe someone has a
hint...
I want to get a fieldinformation of an event from the Control class, e.g.
"TextChanged".
FieldInfo fi = typeof(Control).GetField("TextChanged",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Public);
This should return the FieldInfo of the Control.TextChanged-event.But it
doesn't! It returns null.
If I do the same code on my self defined class, it works perfectly. The only
thing I can guess, is that
I should grant permission with ReflectionPermission. I have the default
settings for security and the
security tool tells me there is no security on the windows.forms-assembly.
Anybody can help me?
Thanks in advance
Dan
Full code below:
-------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
namespace ReflectionTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Tester
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//MyClass
EventInfo ei1 = typeof(MyClass).GetEvent("MyEvent");
FieldInfo fi1 = typeof(MyClass).GetField("MyEvent",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Public);
//Control
EventInfo ei2 = typeof(Control).GetEvent("TextChanged");
FieldInfo fi2 = typeof(Control).GetField("TextChanged",
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Public);
//why is fi2 == null ?????
}
class MyClass
{
public event EventHandler MyEvent;
}
}
}