예제 #1
0
        /// <summary>
        /// 根据构造函数,创建对象委托
        /// </summary>
        /// <param name="classtype">对象类型</param>
        public ClassDispatcher(Type classtype)
        {
            if (classtype == null)
            {
                throw new ArgumentNullException(nameof(classtype), "参数为空!");
            }

            var constructorInfos = classtype.GetConstructors(BindingFlags.Public | BindingFlags.Instance);

            if (constructorInfos.Length == 0)
            {
                throw new Exception(string.Format("类:{0},无法获取到公开的构造函数,无法创建消息体。", classtype.FullName));
            }

            if (constructorInfos.Length > 1)
            {
                throw new Exception(string.Format("类:{0},存在多个构造函数,无法创建消息体。", classtype.FullName));
            }

            this.Parameters = TypeInvoke.GetParameter(constructorInfos[0].GetParameters());

            this.Type = classtype;

            _newclass = GetClass(constructorInfos[0]);
        }
예제 #2
0
        /// <summary>
        /// 根据构造函数,创建对象委托
        /// </summary>
        /// <param name="constructor">构造函数对象</param>
        public ClassDispatcher(ConstructorInfo constructor)
        {
            if (constructor == null)
            {
                throw new ArgumentNullException(nameof(constructor), "参数为空!");
            }

            this.Parameters = TypeInvoke.GetParameter(constructor.GetParameters());

            this.Type = constructor.DeclaringType;

            _newclass = GetClass(constructor);
        }
예제 #3
0
        /// <summary>
        /// 初始化对象
        /// </summary>
        /// <param name="methodInfo">方法对象</param>
        public ActionDispatcher(MethodInfo methodInfo)
        {
            this.IsVoid = methodInfo.ReturnType == typeof(void);

            this.ReturnType = methodInfo.ReturnType;

            this.Method = methodInfo;

            _parameters = TypeInvoke.GetParameter(methodInfo);

            if (this.IsVoid)
            {
                _executorVoid = GetExecutor <T>(methodInfo) as VoidActionExecutor <T>;
            }
            else
            {
                _executor = GetExecutor <T>(methodInfo) as ActionExecutor <T>;
            }
            //_executor = GetExecutor<T>(methodInfo);
            //MethodInfo = methodInfo;
        }