Esempio n. 1
0
        MethodInfo FindMethodInfo(Type serviceType, string calledMethod, XmlNode[] paramNodes)
        {
            var possibleMethods = new MethodInfo[0];
            var parameterInfos  = new ParameterInfo[0];

            var serviceInfo = XmlRpcServiceInfo.CreateServiceInfo(serviceType);

            possibleMethods = serviceInfo.GetMethodInfos(calledMethod);
            if (!possibleMethods.Any())
            {
                throw new XmlRpcUnsupportedMethodException($"unsupported method called: {calledMethod}");
            }

            var methodInfo = possibleMethods.FirstOrDefault(m => m.GetParameters().Length == paramNodes.Length);

            if (methodInfo == null)
            {
                throw new XmlRpcInvalidParametersException($"The method {methodInfo} was called with wrong parameter count");
            }

            var rpcAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(XmlRpcMethodAttribute));

            if (rpcAttribute == null)
            {
                throw new XmlRpcMethodAttributeException($"Method {calledMethod} must be marked with the XmlRpcMethod attribute.");
            }

            return(methodInfo);
        }