public object Call(object obj, ScriptObject[] parameters) { FunctionBase methodInfo = null; FunctionBase functionBase = null; for (int i = 0; i < m_Count; ++i) { functionBase = m_Methods[i]; if (functionBase.IsValid) { if (functionBase.Params) { bool fit = true; int length = functionBase.ParameterType.Length; int length1 = parameters.Length; if (length1 >= length - 1) { for (int j = 0; j < length1; ++j) { if (!Util.CanChangeType(parameters[j], j >= length - 1 ? functionBase.ParamType : functionBase.ParameterType[j])) { fit = false; break; } } } if (fit) { methodInfo = functionBase; break; } } else if (Util.CanChangeType(parameters, functionBase.ParameterType)) { methodInfo = functionBase; break; } } } try { if (methodInfo != null) { int length = methodInfo.ParameterType.Length; object[] objs = methodInfo.Args; if (methodInfo.Params) { for (int i = 0; i < length - 1; ++i) { objs[i] = Util.ChangeType(m_Script, parameters[i], methodInfo.ParameterType[i]); } Array array = Array.CreateInstance(methodInfo.ParamType, parameters.Length - length + 1); for (int i = length - 1; i < parameters.Length; ++i) { array.SetValue(Util.ChangeType(m_Script, parameters[i], methodInfo.ParamType), i - length + 1); } objs[length - 1] = array; return(methodInfo.Invoke(obj, m_Type)); } else { for (int i = 0; i < length; i++) { objs[i] = Util.ChangeType(m_Script, parameters[i], methodInfo.ParameterType[i]); } return(methodInfo.Invoke(obj, m_Type)); } } } catch (System.Exception e) { throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 调用函数出错 [" + MethodName + "] : " + e.ToString()); } throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 找不到合适的函数 [" + MethodName + "]"); }
public object Call(object obj, ScriptObject[] parameters) { try { int parameterNumber = parameters.Length; //脚本传入的参数个数 if (!m_IsClass && parameterNumber == 0) { return(Activator.CreateInstance(m_Type)); } else { FunctionBase methodInfo = null; FunctionBase functionBase = null; for (int i = 0; i < m_Count; ++i) { functionBase = m_Methods[i]; if (functionBase.Params || functionBase.HasDefault) { continue; } if (CheckNormalType(parameters, functionBase.ParameterType, functionBase.ParameterCount)) { methodInfo = functionBase; goto callMethod; } } for (int i = 0; i < m_Count; ++i) { functionBase = m_Methods[i]; if (functionBase.Params || !functionBase.HasDefault) { continue; } if (CheckDefaultType(parameters, functionBase.ParameterType, functionBase.RequiredNumber, functionBase.ParameterCount)) { methodInfo = functionBase; goto callMethod; } } for (int i = 0; i < m_Count; ++i) { functionBase = m_Methods[i]; if (!functionBase.Params) { continue; } if (CheckArgsType(parameters, functionBase.ParameterType, functionBase.ParamType, functionBase.RequiredNumber, functionBase.ParameterCount)) { methodInfo = functionBase; goto callMethod; } } callMethod: if (methodInfo != null) { int requiredNumber = methodInfo.RequiredNumber; //函数必须传入的参数个数 int parameterCount = methodInfo.ParameterCount; //参数个数 object[] args = methodInfo.Args; //参数数组 if (methodInfo.Params) { for (int i = 0; i < parameterCount; ++i) { args[i] = i >= parameterNumber ? methodInfo.DefaultParameter[i - requiredNumber] : Util.ChangeType(m_Script, parameters[i], methodInfo.ParameterType[i]); } if (parameterNumber > parameterCount) { Array array = Array.CreateInstance(methodInfo.ParamType, parameterNumber - parameterCount); for (int i = parameterCount; i < parameterNumber; ++i) { array.SetValue(Util.ChangeType(m_Script, parameters[i], methodInfo.ParamType), i - parameterCount); } args[parameterCount] = array; } else { args[parameterCount] = Array.CreateInstance(methodInfo.ParamType, 0); } return(methodInfo.Invoke(obj, m_Type)); } else { for (int i = 0; i < parameterCount; ++i) { args[i] = i >= parameterNumber ? methodInfo.DefaultParameter[i - requiredNumber] : Util.ChangeType(m_Script, parameters[i], methodInfo.ParameterType[i]); } return(methodInfo.Invoke(obj, m_Type)); } } } } catch (System.Exception e) { throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 调用函数出错 [" + MethodName + "] : " + e.ToString()); } throw new ExecutionException(m_Script, "Type[" + m_Type.ToString() + "] 找不到合适的函数 [" + MethodName + "]"); }
public object Call(object obj, ScriptObject[] parameters) { FunctionBase base2 = null; FunctionBase base3 = null; for (int i = 0; i < this.m_Count; i++) { base3 = this.m_Methods[i]; if ((!base3.Params && !base3.HasDefault) && this.CheckNormalType(parameters, base3.ParameterType, base3.ParameterCount)) { base2 = base3; goto Label_00DF; } } for (int j = 0; j < this.m_Count; j++) { base3 = this.m_Methods[j]; if ((!base3.Params && base3.HasDefault) && this.CheckDefaultType(parameters, base3.ParameterType, base3.RequiredNumber, base3.ParameterCount)) { base2 = base3; goto Label_00DF; } } for (int k = 0; k < this.m_Count; k++) { base3 = this.m_Methods[k]; if (base3.Params && this.CheckArgsType(parameters, base3.ParameterType, base3.ParamType, base3.RequiredNumber, base3.ParameterCount)) { base2 = base3; break; } } Label_00DF: try { if (base2 != null) { int requiredNumber = base2.RequiredNumber; int parameterCount = base2.ParameterCount; int length = parameters.Length; object[] args = base2.Args; if (base2.Params) { for (int n = 0; n < parameterCount; n++) { args[n] = (n >= length) ? base2.DefaultParameter[n - requiredNumber] : Util.ChangeType(this.m_Script, parameters[n], base2.ParameterType[n]); } if (length > parameterCount) { Array array = Array.CreateInstance(base2.ParamType, (int)(length - parameterCount)); for (int num8 = parameterCount; num8 < length; num8++) { array.SetValue(Util.ChangeType(this.m_Script, parameters[num8], base2.ParamType), (int)(num8 - parameterCount)); } args[parameterCount] = array; } else { args[parameterCount] = Array.CreateInstance(base2.ParamType, 0); } return(base2.Invoke(obj, this.m_Type)); } for (int m = 0; m < parameterCount; m++) { args[m] = (m >= length) ? base2.DefaultParameter[m - requiredNumber] : Util.ChangeType(this.m_Script, parameters[m], base2.ParameterType[m]); } return(base2.Invoke(obj, this.m_Type)); } } catch (Exception exception) { throw new ExecutionException(this.m_Script, "Type[" + this.m_Type.ToString() + "] 调用函数出错 [" + this.MethodName + "] : " + exception.ToString()); } throw new ExecutionException(this.m_Script, "Type[" + this.m_Type.ToString() + "] 找不到合适的函数 [" + this.MethodName + "]"); }