示例#1
0
        /// <summary> 应用在基类设置子类属性 </summary>
        public static void SetProperty(this IGroupRelectbject obj, string proName, object proValue)
        {
            Type t = obj.Value.GetType();

            var prop = t.GetProperty(proName);

            prop.SetValue(obj.Value, proValue);
        }
示例#2
0
        /// <summary> 应用在基类获取子类属性 </summary>
        public static object GetProperty(this IGroupRelectbject obj, string proName)
        {
            Type t = obj.Value.GetType();

            var prop = t.GetProperty(proName);

            return(prop.GetValue(obj.Value));
        }
示例#3
0
        /// <summary> 注册事件 </summary>
        public static void AddEvent(this IGroupRelectbject obj, string eventName, MethodInfo method)
        {
            var e = obj.Value.GetType().GetEvent(eventName);

            Delegate dele = Delegate.CreateDelegate(e.DeclaringType, method);

            obj.AddEvent(eventName, dele);
        }
示例#4
0
        /// <summary> 检查指定类型中是否包含指定构造函数 Type[] parameters = { typeof(string),typeof(DataTable) }</summary>
        public static bool IsHaveParamConstruct(this IGroupRelectbject obj, Type[] parameters)
        {
            Type t = obj.Value.GetType();

            System.Reflection.ConstructorInfo ci = t.GetConstructor(parameters);

            return(ci != null);
        }
示例#5
0
        /// <summary> 注册事件 </summary>
        public static void AddEvent(this IGroupRelectbject obj, string eventName, Delegate dele)
        {
            Type t = obj.Value.GetType();

            var ev = t.GetEvent(eventName);

            ev.AddEventHandler(obj, dele);
        }
示例#6
0
        /// <summary> 执行指定方法 </summary>
        public static object InvokeMethod(this IGroupRelectbject obj, string methodName, params object[] parameters)
        {
            Type t = obj.Value.GetType();

            Type[] paramsTypes = parameters.Select(l => l.GetType()).ToArray();

            var method = t.GetMethod(methodName, paramsTypes);

            return(method.Invoke(obj, parameters));
        }
示例#7
0
        /// <summary> 是否包含指定事件 </summary>
        public static bool IsHaveRegisterEvent(this IGroupRelectbject obj, string eventName, string registerMethodName)
        {
            Type t = obj.Value.GetType();

            var ev = t.GetEvent(eventName);

            Delegate[] ds = ev.As <IGroupRelectbject>().GetObjectEventList(eventName);

            return(ds.ToList().Exists(l => l.Method.Name == registerMethodName));
        }
示例#8
0
        /// <summary> 清空指定事件 </summary>
        public static void ClearEvent(this IGroupRelectbject obj, string eventName)
        {
            Type t = obj.Value.GetType();

            var ev = t.GetEvent(eventName);

            var deles = obj.As <IGroupRelectbject>().GetObjectEventList(eventName);

            // Todo :执行委托方法
            foreach (var item in deles)
            {
                ev.RemoveEventHandler(obj, item);
            }
        }
示例#9
0
        /// <summary> 执行指定事件的所有委托 </summary>
        public static void InvokeEvent(this IGroupRelectbject obj, string eventName, params object[] parameters)
        {
            var deles = obj.As <IGroupRelectbject>().GetObjectEventList(eventName);

            if (deles == null)
            {
                return;
            }

            // Todo :执行委托方法
            foreach (var item in deles)
            {
                item.DynamicInvoke(parameters);
            }
        }
示例#10
0
        /// <summary> 获取指定事件的所有注册委托 </summary>
        public static Delegate[] GetObjectEventList(this IGroupRelectbject obj, string p_EventName)
        {
            Type t = obj.Value.GetType();

            var _PropertyInfo = t.GetField(p_EventName, BindingFlags.Instance | BindingFlags.NonPublic);

            if (_PropertyInfo == null)
            {
                return(null);
            }

            Delegate _EventList = (Delegate)_PropertyInfo.GetValue(obj.Value);

            if (_EventList == null)
            {
                return(null);
            }

            return(_EventList.GetInvocationList());
        }
示例#11
0
        /// <summary> 类型名称 </summary>
        public static string NameOf(this IGroupRelectbject obj)
        {
            Type t = obj.Value.GetType();

            return(t.Name);
        }
示例#12
0
 /// <summary> 检查指定类型中是否包含无参数构造函数 </summary>
 public static bool IsHaveNoParamConstruct(this IGroupRelectbject obj, Type[] parameters)
 {
     return(obj.IsHaveParamConstruct(Type.EmptyTypes));
 }
示例#13
0
        /// <summary> 判断两个类型的关系类型不可以是接口 用法:子类.IsSubClassOf(父类) </summary>
        public static bool IsSubclassOf <T>(this IGroupRelectbject obj)
        {
            Type t = obj.Value.GetType();

            return(t.IsSubclassOf(typeof(T)));
        }
示例#14
0
        /// <summary> 判断对象是否是指定类型型可以是父类,接口 用法:父类.IsInstanceOfType(子类对象)</summary>
        public static bool IsInstanceOfType <T>(this IGroupRelectbject obj)
        {
            Type t = obj.Value.GetType();

            return(t.IsInstanceOfType(typeof(T)));
        }
示例#15
0
        /// <summary> 判断两个类型的关系类型可以是父类,接口 用法:父类.IsAssignableFrom(子类)</summary>
        public static bool IsAssignableFrom <T>(this IGroupRelectbject obj)
        {
            Type t = obj.Value.GetType();

            return(t.IsAssignableFrom(typeof(T)));
        }