Get Event Info - CSharp System.Reflection

CSharp examples for System.Reflection:Event

Description

Get Event Info

Demo Code


using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
using System.ComponentModel;
using System.Collections.Generic;
using System;/* ww w.  ja v  a2s . c om*/

public class Main{
        private static EventInfo GetEventInfo(object instance, string eventName) {
            if (instance == null) {
                throw new ArgumentNullException("instance");
            }
            if (String.IsNullOrEmpty(eventName)) {
                throw new ArgumentException("An event must be specified.", "eventName");
            }
            EventInfo eventInfo = instance.GetType().GetEvent(eventName);
            if (eventInfo == null) {
                throw new ArgumentException(String.Format(
                    "An event named '{0}' on type '{1}' could not be found.",
                    eventName, instance.GetType().FullName));
            }
            return eventInfo;
        }
}

Related Tutorials