示例#1
0
        public static void ExecuteMethod(object methodSource, string methodName, bool ignorExecute = false)
        {
            methodSource = methodSource ?? throw new NullReferenceException("Method source can not be null.");
            var action = ReflectionCash.GetDelegateWithoutParameter(methodSource.GetType(), methodName) ??
                         throw new InvalidOperationException($"Can not find method {methodName} in object of type {methodSource.GetType()}.");

            if (!ignorExecute)
            {
                action(methodSource);
            }
        }
示例#2
0
        public static EventInfo GetDefaultEvent(Type eventSource)
        {
            var e = _DefaultEvent.GetValue(eventSource, () =>
            {
                var a = eventSource.GetCustomAttribute <System.ComponentModel.DefaultEventAttribute>()
                        ?? throw new InvalidOperationException($"Type {eventSource.Name} does not own a default event.");
                return(ReflectionCash.GetEvent(eventSource, a.Name));
            });

            if (e == null)
            {
                e = GetEvents(eventSource).FirstOrDefault();
            }
            return(e);
        }
示例#3
0
 public static void ClearDefaultEvents() => ReflectionCash.ClearDefaultEvents();
示例#4
0
 public static void ClearDefaultEvent(Type type) => ReflectionCash.ClearDefaultEvent(type);
示例#5
0
 public static bool SetDefaultEventIfNotExist(Type type, string eventName) => ReflectionCash.SetDefaultEventIfNotExist(type, eventName);
示例#6
0
 public static void SetDefaultEvent(Type type, string eventName) => ReflectionCash.SetDefaultEvent(type, eventName);
示例#7
0
 public static bool HasDefaultEvent(Type type) => ReflectionCash.HasDefaultEvent(type);