コード例 #1
0
        public static IEnumerable <CallbackDescriptor> GetEventHandlerListEvents(this object value)
        {
            Func <PropertyInfo, bool> selector = pi => string.Compare(pi.Name, "Events", false) == 0;
            var listInfo = value.NonPublicInstanceProperties(selector).SingleOrDefault();

            if (listInfo == null)
            {
                return(Enumerable.Empty <CallbackDescriptor>());
            }

            var events = from fi in value.NonPublicStaticFields(true)
                         let list = listInfo.GetValue <EventHandlerList>(value, null)
                                    from handlerEntry in list.AsEnumerable()
                                    where handlerEntry.Key == fi.GetValue(value) &&
                                    handlerEntry.Handler != null
                                    select new
            {
                fi.Name,
                handlerEntry.Handler
            };

            return(events.Select(e =>
            {
                var callbackDescriptor = new CallbackDescriptor(e.Name);
                callbackDescriptor.AddMethods(e.Handler.GetInvocationList().Select(del => del.Method));
                return callbackDescriptor;
            }).ToArray());
        }
コード例 #2
0
 public static IEnumerable <CallbackDescriptor> GetPocoEventsForTypes(object value, params Type[] types)
 {
     return(value.GetInstanceFields()
            .Where(fi => types.Any(t => t.IsAssignableFrom(fi.FieldType)) && fi.GetValue <Delegate>(value) != null)
            .Select(e =>
     {
         var callbackDescriptor = new CallbackDescriptor(e.Name);
         var eventDelegate = e.GetValue <Delegate>(value);
         callbackDescriptor.AddMethods(eventDelegate.GetInvocationList().Select(del => del.Method));
         return callbackDescriptor;
     }).ToArray());
 }