Inheritance: System.Attribute
Esempio n. 1
0
        static void ExtractMethodInfo(Hashtable methods, MethodInfo mi)
        {
            XmlRpcMethodAttribute attr = (XmlRpcMethodAttribute)
                                         Attribute.GetCustomAttribute(mi,
                                                                      typeof(XmlRpcMethodAttribute));

            if (attr == null)
            {
                return;
            }

            XmlRpcMethodInfo mthdInfo = (XmlRpcMethodInfo)methods[mi.Name];

            if (mthdInfo == null)
            {
                mthdInfo = new XmlRpcMethodInfo();
                methods.Add(mi.Name, mthdInfo);
            }

            mthdInfo.MethodInfo = mi;
            mthdInfo.XmlRpcName = GetXmlRpcMethodName(mi);
            mthdInfo.MiName     = mi.Name;
            mthdInfo.Doc        = attr.Description;
            mthdInfo.IsHidden   = attr.IntrospectionMethod | attr.Hidden;
            // extract parameters information
            ArrayList parmList = new ArrayList();

            ParameterInfo[] parms = mi.GetParameters();
            foreach (ParameterInfo parm in parms)
            {
                XmlRpcParameterInfo parmInfo = new XmlRpcParameterInfo();
                parmInfo.Name       = parm.Name;
                parmInfo.Type       = parm.ParameterType;
                parmInfo.XmlRpcType = GetXmlRpcTypeString(parm.ParameterType);
                // retrieve optional attributed info
                parmInfo.Doc = "";
                XmlRpcParameterAttribute pattr = (XmlRpcParameterAttribute)
                                                 Attribute.GetCustomAttribute(parm,
                                                                              typeof(XmlRpcParameterAttribute));
                if (pattr != null)
                {
                    parmInfo.Doc        = pattr.Description;
                    parmInfo.XmlRpcName = pattr.Name;
                }
                parmList.Add(parmInfo);
            }
            mthdInfo.Parameters = (XmlRpcParameterInfo[])
                                  parmList.ToArray(typeof(XmlRpcParameterInfo));
            // extract return type information
            mthdInfo.ReturnType       = mi.ReturnType;
            mthdInfo.ReturnXmlRpcType = GetXmlRpcTypeString(mi.ReturnType);
            object[] orattrs = mi.ReturnTypeCustomAttributes.GetCustomAttributes(
                typeof(XmlRpcReturnValueAttribute), false);
            if (orattrs.Length > 0)
            {
                mthdInfo.ReturnDoc = ((XmlRpcReturnValueAttribute)orattrs[0]).Description;
            }
        }
        bool IsVisibleXmlRpcMethod(MethodInfo mi)
        {
            bool      ret  = false;
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));

            if (attr != null)
            {
                XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)attr;
                ret = !mattr.Hidden;
            }
            return(ret);
        }
Esempio n. 3
0
        static bool IsVisibleXmlRpcMethod(MethodInfo mi)
        {
            bool      ret  = false;
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));

            if (attr != null)
            {
                XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)attr;
                ret = !(mattr.Hidden || mattr.IntrospectionMethod == true);
            }
            return(ret);
        }
Esempio n. 4
0
        public bool IsStructParamsMethod(MethodInfo mi)
        {
            if (mi == null)
            {
                return(false);
            }
            bool      ret  = false;
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));

            if (attr != null)
            {
                XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)attr;
                ret = mattr.StructParams;
            }
            return(ret);
        }
Esempio n. 5
0
        public static string GetXmlRpcMethodName(MethodInfo mi)
        {
            XmlRpcMethodAttribute attr = (XmlRpcMethodAttribute)
                                         Attribute.GetCustomAttribute(mi,
                                                                      typeof(XmlRpcMethodAttribute));

            if (attr != null &&
                attr.Method != null &&
                attr.Method != "")
            {
                return(attr.Method);
            }
            else
            {
                return(mi.Name);
            }
        }
Esempio n. 6
0
        string GetRpcMethodName(object clientObj, string MethodName)
        {
            string rpcMethod;
            // extract method name from Proxy type info
            Type       type = clientObj.GetType();
            MethodInfo mi   = type.GetMethod(MethodName);

            if (mi == null)
            {
                throw new Exception("Invoke on non-existent or non-public proxy method");
            }
            // first check if specified method is a Begin async method
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcBeginAttribute));

            if (attr != null)
            {
                rpcMethod = ((XmlRpcBeginAttribute)attr).Method;
                if (rpcMethod == "")
                {
                    if (!MethodName.StartsWith("Begin") || MethodName.Length <= 5)
                    {
                        throw new Exception(String.Format(
                                                "method {0} has invalid signature for begin method",
                                                MethodName));
                    }
                    rpcMethod = MethodName.Substring(5);
                }
                return(rpcMethod);
            }
            // if no XmlRpcBegin attribute, must have XmlRpcMethod attribute
            attr = Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute));
            if (attr == null)
            {
                throw new Exception("missing method attribute");
            }
            XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;

            rpcMethod = xrmAttr.Method;
            if (rpcMethod == "")
            {
                rpcMethod = mi.Name;
            }
            return(rpcMethod);
        }
Esempio n. 7
0
        private static string GetXmlRpcMethodName(MethodInfo mi)
        {
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));

            if (attr == null)
            {
                return(null);
            }
            XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;
            string rpcMethod = xrmAttr.Method;

            if (rpcMethod == "")
            {
                rpcMethod = mi.Name;
            }
            return(rpcMethod);
        }
Esempio n. 8
0
 private static void BuildMethods(TypeBuilder tb, IEnumerable <MethodData> methods)
 {
     foreach (MethodData mthdData in methods)
     {
         MethodInfo mi         = mthdData.mi;
         Type[]     argTypes   = new Type[mi.GetParameters().Length];
         string[]   paramNames = new string[mi.GetParameters().Length];
         for (int i = 0; i < mi.GetParameters().Length; i++)
         {
             argTypes[i]   = mi.GetParameters()[i].ParameterType;
             paramNames[i] = mi.GetParameters()[i].Name;
         }
         XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)
                                       Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute));
         BuildMethod(tb, mi.Name, mthdData.xmlRpcName, paramNames, argTypes,
                     mthdData.paramsMethod, mi.ReturnType, mattr.StructParams);
     }
 }
Esempio n. 9
0
        string GetRpcMethodName(MethodInfo mi)
        {
            Attribute attr = Attribute.GetCustomAttribute(mi,
                                                          typeof(XmlRpcMethodAttribute));
            // TODO: do methods need attribute?
            //      if (attr == null)
            //      {
            //        throw new Exception("missing method attribute");
            //      }
            string rpcMethod = "";

            if (attr != null)
            {
                XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;
                rpcMethod = xrmAttr.Method;
            }
            if (rpcMethod == "")
            {
                rpcMethod = mi.Name;
            }
            return(rpcMethod);
        }
Esempio n. 10
0
        string GetRpcMethodName(object clientObj, MethodInfo mi)
        {
            string    rpcMethod;
            string    MethodName = mi.Name;
            Attribute attr       = Attribute.GetCustomAttribute(mi,
                                                                typeof(XmlRpcBeginAttribute));

            if (attr != null)
            {
                rpcMethod = ((XmlRpcBeginAttribute)attr).Method;
                if (rpcMethod == "")
                {
                    if (!MethodName.StartsWith("Begin") || MethodName.Length <= 5)
                    {
                        throw new Exception(String.Format(
                                                "method {0} has invalid signature for begin method",
                                                MethodName));
                    }
                    rpcMethod = MethodName.Substring(5);
                }
                return(rpcMethod);
            }
            // if no XmlRpcBegin attribute, must have XmlRpcMethod attribute
            attr = Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute));
            if (attr == null)
            {
                throw new Exception("missing method attribute");
            }
            XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;

            rpcMethod = xrmAttr.Method;
            if (rpcMethod == "")
            {
                rpcMethod = mi.Name;
            }
            return(rpcMethod);
        }
Esempio n. 11
0
        static void ExtractMethodInfo(Dictionary <string, XmlRpcMethodInfo> methods,
                                      MethodInfo mi, Type type)
        {
            XmlRpcMethodAttribute attr = (XmlRpcMethodAttribute)
                                         Attribute.GetCustomAttribute(mi,
                                                                      typeof(XmlRpcMethodAttribute));

            if (attr == null)
            {
                return;
            }
            XmlRpcMethodInfo mthdInfo = new XmlRpcMethodInfo();

            mthdInfo.MethodInfo = mi;
            mthdInfo.XmlRpcName = XmlRpcTypeInfo.GetXmlRpcMethodName(mi);
            mthdInfo.MiName     = mi.Name;
            mthdInfo.Doc        = attr.Description;
            mthdInfo.IsHidden   = attr.IntrospectionMethod | attr.Hidden;
            // extract parameters information
            var parmList = new List <XmlRpcParameterInfo>();

            ParameterInfo[] parms = mi.GetParameters();
            foreach (ParameterInfo parm in parms)
            {
                XmlRpcParameterInfo parmInfo = new XmlRpcParameterInfo();
                parmInfo.Name       = parm.Name;
                parmInfo.Type       = parm.ParameterType;
                parmInfo.XmlRpcType = XmlRpcTypeInfo.GetXmlRpcTypeString(parm.ParameterType);
                // retrieve optional attributed info
                parmInfo.Doc = "";
                XmlRpcParameterAttribute pattr = (XmlRpcParameterAttribute)
                                                 Attribute.GetCustomAttribute(parm,
                                                                              typeof(XmlRpcParameterAttribute));
                if (pattr != null)
                {
                    parmInfo.Doc        = pattr.Description;
                    parmInfo.XmlRpcName = pattr.Name;
                }
                parmInfo.IsParams = Attribute.IsDefined(parm,
                                                        typeof(ParamArrayAttribute));
                parmList.Add(parmInfo);
            }
            mthdInfo.Parameters = parmList.ToArray();
            // extract return type information
            mthdInfo.ReturnType       = mi.ReturnType;
            mthdInfo.ReturnXmlRpcType = XmlRpcTypeInfo.GetXmlRpcTypeString(mi.ReturnType);
            object[] orattrs = mi.ReturnTypeCustomAttributes.GetCustomAttributes(
                typeof(XmlRpcReturnValueAttribute), false);
            if (orattrs.Length > 0)
            {
                mthdInfo.ReturnDoc = ((XmlRpcReturnValueAttribute)orattrs[0]).Description;
            }

            if (methods.ContainsKey(mthdInfo.XmlRpcName))
            {
                throw new XmlRpcDupXmlRpcMethodNames(String.Format("Method "
                                                                   + "{0} in type {1} has duplicate XmlRpc method name {2}",
                                                                   mi.Name, type.Name, mthdInfo.XmlRpcName));
            }
            else
            {
                methods.Add(mthdInfo.XmlRpcName, mthdInfo);
            }
        }