Esempio n. 1
0
    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
      var methods = new Dictionary<string, XmlRpcMethodInfo>();

      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, itf);
        }
#else
        foreach (MethodInfo mi in itf.GetMethods())
        {
          ExtractMethodInfo(methods, mi, itf);
        }
#endif
      }

      foreach (MethodInfo mi in type.GetMethods())
      {
        var mthds = new List<MethodInfo>();
        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, type);
        }
      }
      svcInfo.methodInfos = new XmlRpcMethodInfo[methods.Count];
      methods.Values.CopyTo(svcInfo.methodInfos, 0);
      Array.Sort(svcInfo.methodInfos);
      return svcInfo;
    }
Esempio n. 2
0
        public static XmlRpcServiceInfo CreateServiceInfo(Type type)
        {
            var svcInfo = new XmlRpcServiceInfo();
            // extract service info
            var svcAttr = Attribute.GetCustomAttribute(type, typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
            if (svcAttr != null && !string.IsNullOrEmpty(svcAttr.Description))
                svcInfo.Doc = svcAttr.Description;

            if (svcAttr != null && !string.IsNullOrEmpty(svcAttr.Name))
                svcInfo.Name = svcAttr.Name;
            else
                svcInfo.Name = type.Name;

            // extract method info
            var methods = new Dictionary<string, XmlRpcMethodInfo>();

            foreach (Type itf in type.GetInterfaces())
            {
                var itfAttr = Attribute.GetCustomAttribute(itf, typeof(XmlRpcServiceAttribute)) as XmlRpcServiceAttribute;
                if (itfAttr != null)
                    svcInfo.Doc = itfAttr.Description;

                var imap = type.GetInterfaceMap(itf);
                foreach (var mi in imap.InterfaceMethods)
                    ExtractMethodInfo(methods, mi, itf);
            }

            foreach (var mi in type.GetMethods())
            {
                var mthds = new List<MethodInfo>();
                mthds.Add(mi);

                var curMi = mi;
                while (true)
                {
                    var baseMi = curMi.GetBaseDefinition();
                    if (baseMi.DeclaringType == curMi.DeclaringType)
                        break;

                    mthds.Insert(0, baseMi);
                    curMi = baseMi;
                }

                foreach (var mthd in mthds)
                    ExtractMethodInfo(methods, mthd, type);
            }

            svcInfo._methodInfos = new XmlRpcMethodInfo[methods.Count];
            methods.Values.CopyTo(svcInfo._methodInfos, 0);
            Array.Sort(svcInfo._methodInfos);
            return svcInfo;
        }