Exemplo n.º 1
0
        private DynamicMethodInfo GetExcuteMethodProxy(object container, string methodName, object[] args)
        {
            Type   type = container.GetType();
            string key  = string.Concat("m.", TypeToName(type), ".", methodName);

            DynamicMethodInfo[] list;

            if ((list = CacheHelpers.Get <DynamicMethodInfo[]>(key)) == null)
            {
                list = CreateDynamicMethods(type, methodName);
                CacheHelpers.Set(key, list);
            }
            if (list != null && list.Length > 0)
            {
                var argsType = new Type[args.Length];
                for (var i = 0; i < args.Length; i++)
                {
                    if (args[i] != null)
                    {
                        argsType[i] = args[i].GetType();
                    }
                }
                var m = DynamicHelpers.GetDynamicMethod(methodName, list, argsType);
                if (m != null)
                {
                    m.IsMatchParameters = true;
                    return(m);
                }


                //可选参数
                if (argsType.Length == 1 && argsType[0] != null && argsType[0] == typeof(Dictionary <object, object>) &&
                    (list[0].Parameters.Length != 1 || !list[0].Parameters[0].ParameterType.IsSubclassOf(typeof(IDictionary))))
                {
                    m = list[0];
                    m.IsMatchParameters = false;
                    return(m);
                }
            }

            return(null);
        }