public DynMethodInstance(string interfaceName, string methodName)
        {
            DynMethod dynMethod = DynTypeManager.GetInterface(interfaceName).GetMethod(methodName);

            if (dynMethod == null)
            {
                throw new ApplicationException(string.Format("接口【{0}】下面找不到,方法名为【{1}】的方法", interfaceName, methodName));
            }

            _dynMethod = dynMethod;
            _fullName  = interfaceName + "_" + methodName;

            foreach (DynParameter dynParameter in _dynMethod.GetParameters())
            {
                SetDefaultValue(dynParameter);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 获取方法
 /// </summary>
 /// <param name="methodName">方法名称</param>
 /// <returns>动态方法</returns>
 public DynMethod GetMethod(string methodName)
 {
     if (!string.IsNullOrEmpty(methodName))
     {
         DynMethod method = null;
         if (_methods.TryGetValue(methodName, out method))
         {
             return(method);
         }
         else
         {
             throw new ApplicationException(string.Format("当前类{0}不存在方法名为{1}的方法", _name, methodName));
         }
     }
     else
     {
         throw new ApplicationException("方法名不能为空或null");
     }
 }
Beispiel #3
0
 /// <summary>
 /// 添加方法
 /// </summary>
 /// <param name="method">动态方法</param>
 public void AddMethod(DynMethod method)
 {
     if (method != null)
     {
         if (!_methods.ContainsKey(method.Name))
         {
             _methods.Add(method.Name, method);
             method.ClassName = _name;
         }
         else
         {
             throw new ApplicationException(string.Format("当前接口{0}已经存在名为{1}的方法", _name, method.Name));
         }
     }
     else
     {
         throw new ApplicationException("方法不能为null");
     }
 }
Beispiel #4
0
 /// <summary>
 /// 添加方法
 /// </summary>
 /// <param name="method">动态方法</param>
 public void AddMethod(DynMethod method)
 {
     if (method != null)
     {
         DynMethod oldmethod = null;
         if (!_methods.TryGetValue(method.Name, out oldmethod))
         {
             _methods.Add(method.Name, method);
             method.ClassName = _name;
         }
         else
         {
             throw new ApplicationException(string.Format("当前类{0}已经存在名为{1}的方法", _name, oldmethod.Name));
         }
     }
     else
     {
         throw new ApplicationException("方法不能为null");
     }
 }
        private void eval_AdditionalFunctionEventHandler(object sender, AdditionalFunctionEventArgs e)
        {
            object[] parameters = e.GetParameters();
            object   value;

            //检查是否在默认的函数库中
            switch (e.Name)
            {
            case "GetProperty":
                break;

            case "Get":
                if (Context == null)
                {
                    throw new ApplicationException("执行函数失败 上下文为空");
                }

                if (Context == null || parameters == null || parameters.Length < 1 || string.IsNullOrEmpty(parameters[0] as string))
                {
                    throw new ApplicationException("执行函数失败 入参输入为空");
                }
                if (!Context.TryGetValue(parameters[0] as string, out value))
                {
                    throw new ApplicationException("执行函数失败 获取上下文时 没有键为" + parameters[0] + "的值");
                }
                e.ReturnValue = value;
                return;

            default:
                string className = null;
                //检查是否在当前应用的函数库中
                if (DynStringResolver.MethodDict.TryGetValue(e.Name, out className))
                {
                    string methodName = e.Name;

                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    DynClass function = DynTypeManager.GetFunction(className);

                    if (function == null)
                    {
                        throw new ApplicationException("执行函数失败 没有主键为" + className + "的函数类 请查看初始化");
                    }
                    DynMethod method = function.GetMethod(methodName);

                    DynParameter[] dynParameters = method.GetParameters();

                    for (int i = 0; i < dynParameters.Length; i++)
                    {
                        value = parameters.Length > i ? parameters[i] : null;

                        switch (dynParameters[i].CollectionType)
                        {
                        case CollectionType.None:
                            value = DynStringResolver.GetTrueType(value, dynParameters[i].DynType);
                            break;

                        case CollectionType.List:
                            IList valueList = value as IList;
                            for (int j = 0; j < valueList.Count; j++)
                            {
                                valueList[j] = DynStringResolver.GetTrueType(valueList[j], dynParameters[i].DynType);
                            }
                            break;

                        case CollectionType.Set:
                        case CollectionType.Map:
                            break;

                        default:
                            break;
                        }

                        dict.Add(dynParameters[i].Name, value);
                    }

                    e.ReturnValue = DynTypeManager.MethodHandler(null, className + "_" + methodName, dict);
                }
                else
                {
                    throw new ApplicationException("无此函数:" + e.Name);
                }
                break;
            }
        }