Use reflection to get the Elapsed event : Event « Reflection « C# / C Sharp






Use reflection to get the Elapsed event

  
using System;
using System.Reflection;
using System.Reflection.Emit;

public class Example
{
    private static object timer;

    public static void Main()
    {
        string fullName = "";
        foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
        {
            if (assem.GetName().Name == "mscorlib")
            {
                fullName = assem.FullName;
            }
        }
        Assembly sys = Assembly.Load("System" + fullName.Substring(fullName.IndexOf(",")));
        Type t = sys.GetType("System.Timers.Timer");
        timer = Activator.CreateInstance(t);

        EventInfo eInfo = t.GetEvent("Elapsed");

    }
}

   
    
  








Related examples in the same category

1.Show Events
2.EventInfo Class discovers the attributes of an event and provides access to event metadata.
3.Get event handler type
4.EventInfo.EventHandlerType
5.Returns the EventInfo object representing the specified public event.
6.Returns the EventInfo object representing the specified event, using the specified binding constraints.
7.Search for events that are declared or inherited by the current Type, using the specified binding constraints.
8.Returns all the public events that are declared or inherited by the current Type.