CookComputing.XmlRpc.XmlRpcServiceInfo.CreateServiceInfo C# (CSharp) Method

CreateServiceInfo() public static method

public static CreateServiceInfo ( Type type ) : XmlRpcServiceInfo
type System.Type
return XmlRpcServiceInfo
        public static XmlRpcServiceInfo CreateServiceInfo(Type type)
        {
            XmlRpcServiceInfo svcInfo = new XmlRpcServiceInfo();
              // extract service info
              XmlRpcServiceAttribute svcAttr = (XmlRpcServiceAttribute)
            Attribute.GetCustomAttribute(type, typeof(XmlRpcServiceAttribute));
              if (svcAttr != null && svcAttr.Description != "")
            svcInfo.doc = svcAttr.Description;
              if (svcAttr != null && svcAttr.Name != "")
            svcInfo.Name = svcAttr.Name;
              else
            svcInfo.Name = type.Name;
              // extract method info
              Hashtable methods = new Hashtable();

              foreach(Type itf in type.GetInterfaces())
              {
            XmlRpcServiceAttribute itfAttr = (XmlRpcServiceAttribute)
              Attribute.GetCustomAttribute(itf, typeof(XmlRpcServiceAttribute));
            if (itfAttr != null)
              svcInfo.doc = itfAttr.Description;
            #if (!COMPACT_FRAMEWORK)
            InterfaceMapping imap = type.GetInterfaceMap(itf);
            foreach (MethodInfo mi in imap.InterfaceMethods)
            {
              ExtractMethodInfo(methods, mi);
            }
            #else
            foreach (MethodInfo mi in itf.GetMethods())
            {
              ExtractMethodInfo(methods, mi);
            }
            #endif
              }

              foreach (MethodInfo mi in type.GetMethods())
              {
            ArrayList mthds = new ArrayList();
            mthds.Add(mi);
            MethodInfo curMi = mi;
            while (true)
            {
              MethodInfo baseMi = curMi.GetBaseDefinition();
              if (baseMi.DeclaringType == curMi.DeclaringType)
            break;
              mthds.Insert(0, baseMi);
              curMi = baseMi;
            }
            foreach(MethodInfo mthd in mthds)
            {
              ExtractMethodInfo(methods, mthd);
            }
              }
              svcInfo.methodInfos = new XmlRpcMethodInfo[methods.Count];
              methods.Values.CopyTo(svcInfo.methodInfos, 0);
              Array.Sort(svcInfo.methodInfos);
              return svcInfo;
        }

Usage Example

Esempio n. 1
0
        public Array System__Method__Signature___(string MethodName)
        {
            //TODO: support overloaded methods
            XmlRpcServiceInfo svcInfo = XmlRpcServiceInfo.CreateServiceInfo(
                this.GetType());
            XmlRpcMethodInfo mthdInfo = svcInfo.GetMethod(MethodName);

            if (mthdInfo == null)
            {
                throw new XmlRpcFaultException("880",
                                               "Request for information on unsupported method");
            }
            if (mthdInfo.IsHidden)
            {
                throw new XmlRpcFaultException("881",
                                               "Information not available on this method");
            }
            //XmlRpcTypes.CheckIsXmlRpcMethod(mi);
            ArrayList alist = new ArrayList();

            alist.Add(XmlRpcServiceInfo.GetXmlRpcTypeString(mthdInfo.ReturnType));
            foreach (XmlRpcParameterInfo paramInfo in mthdInfo.Parameters)
            {
                alist.Add(XmlRpcServiceInfo.GetXmlRpcTypeString(paramInfo.Type));
            }
            string[]  types    = (string[])alist.ToArray(typeof(string));
            ArrayList retalist = new ArrayList();

            retalist.Add(types);
            Array retarray = retalist.ToArray(typeof(string[]));

            return(retarray);
        }
All Usage Examples Of CookComputing.XmlRpc.XmlRpcServiceInfo::CreateServiceInfo