public XsltExtensionFunction(object extension, MethodInfo method, XPathNavigator currentNode) { this.extension = extension; this.method = method; ParameterInfo[] parameters = method.GetParameters(); int num = parameters.Length; int maxArgs = parameters.Length; this.typeCodes = new TypeCode[parameters.Length]; XPathResultType[] array = new XPathResultType[parameters.Length]; bool flag = true; int num2 = parameters.Length - 1; while (0 <= num2) { this.typeCodes[num2] = Type.GetTypeCode(parameters[num2].ParameterType); array[num2] = XPFuncImpl.GetXPathType(parameters[num2].ParameterType, currentNode); if (flag) { if (parameters[num2].IsOptional) { num--; } else { flag = false; } } num2--; } base.Init(num, maxArgs, XPFuncImpl.GetXPathType(method.ReturnType, currentNode), array); }
private MethodInfo FindBestMethod(Type t, string name, XPathResultType[] argTypes, bool isScript) { MethodInfo[] methods = t.GetMethods(((!isScript) ? BindingFlags.Public : (BindingFlags.Public | BindingFlags.NonPublic)) | BindingFlags.Instance | BindingFlags.Static); if (methods.Length == 0) { return(null); } if (argTypes == null) { return(methods[0]); } int num = 0; int num2 = argTypes.Length; for (int i = 0; i < methods.Length; i++) { if (methods[i].Name == name && methods[i].GetParameters().Length == num2) { methods[num++] = methods[i]; } } int num3 = num; if (num3 == 0) { return(null); } if (num3 == 1) { return(methods[0]); } for (int j = 0; j < num3; j++) { bool flag = true; ParameterInfo[] parameters = methods[j].GetParameters(); for (int k = 0; k < parameters.Length; k++) { XPathResultType xpathResultType = argTypes[k]; if (xpathResultType != XPathResultType.Any) { XPathResultType xpathType = XPFuncImpl.GetXPathType(parameters[k].ParameterType, this.p.CurrentNode); if (xpathType != xpathResultType && xpathType != XPathResultType.Any) { flag = false; break; } if (xpathType == XPathResultType.Any && xpathResultType != XPathResultType.NodeSet && parameters[k].ParameterType != typeof(object)) { flag = false; break; } } } if (flag) { return(methods[j]); } } return(null); }
MethodInfo FindBestMethod(Type t, string name, XPathResultType [] argTypes, bool isScript) { int free, length; MethodInfo [] mi = t.GetMethods((isScript ? BF.Public | BF.NonPublic : BF.Public) | BF.Instance | BF.Static); if (mi.Length == 0) { return(null); } if (argTypes == null) { return(mi [0]); // if we dont have info on the arg types, nothing we can do } free = 0; // filter on name + num args int numArgs = argTypes.Length; for (int i = 0; i < mi.Length; i++) { if (mi [i].Name == name && mi [i].GetParameters().Length == numArgs) { mi [free++] = mi [i]; } } length = free; // No method if (length == 0) { return(null); } // Thats it! if (length == 1) { return(mi [0]); } free = 0; for (int i = 0; i < length; i++) { bool match = true; ParameterInfo [] pi = mi [i].GetParameters(); for (int par = 0; par < pi.Length; par++) { XPathResultType required = argTypes [par]; if (required == XPathResultType.Any) { continue; // dunno what it is } XPathResultType actual = XPFuncImpl.GetXPathType(pi [par].ParameterType, p.CurrentNode); if (actual != required && actual != XPathResultType.Any) { match = false; break; } if (actual == XPathResultType.Any) { // try to get a stronger gind if (required != XPathResultType.NodeSet && !(pi [par].ParameterType == typeof(object))) { match = false; break; } } } if (match) { return(mi [i]); // TODO look for exact match } } return(null); }