Beispiel #1
0
        internal HttpClientType(Type type)
        {
            LogicalMethodInfo[] infoArray      = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync);
            Hashtable           formatterTypes = new Hashtable();

            for (int i = 0; i < infoArray.Length; i++)
            {
                LogicalMethodInfo info = infoArray[i];
                try
                {
                    object[] customAttributes = info.GetCustomAttributes(typeof(HttpMethodAttribute));
                    if (customAttributes.Length != 0)
                    {
                        HttpMethodAttribute attribute = (HttpMethodAttribute)customAttributes[0];
                        HttpClientMethod    method    = new HttpClientMethod {
                            readerType = attribute.ReturnFormatter,
                            writerType = attribute.ParameterFormatter,
                            methodInfo = info
                        };
                        AddFormatter(formatterTypes, method.readerType, method);
                        AddFormatter(formatterTypes, method.writerType, method);
                        this.methods.Add(info.Name, method);
                    }
                }
                catch (Exception exception)
                {
                    if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                    {
                        throw;
                    }
                    throw new InvalidOperationException(Res.GetString("WebReflectionError", new object[] { info.DeclaringType.FullName, info.Name }), exception);
                }
            }
            foreach (Type type2 in formatterTypes.Keys)
            {
                ArrayList           list        = (ArrayList)formatterTypes[type2];
                LogicalMethodInfo[] methodInfos = new LogicalMethodInfo[list.Count];
                for (int j = 0; j < list.Count; j++)
                {
                    methodInfos[j] = ((HttpClientMethod)list[j]).methodInfo;
                }
                object[] initializers = MimeFormatter.GetInitializers(type2, methodInfos);
                bool     flag         = typeof(MimeParameterWriter).IsAssignableFrom(type2);
                for (int k = 0; k < list.Count; k++)
                {
                    if (flag)
                    {
                        ((HttpClientMethod)list[k]).writerInitializer = initializers[k];
                    }
                    else
                    {
                        ((HttpClientMethod)list[k]).readerInitializer = initializers[k];
                    }
                }
            }
        }
        internal HttpClientType(Type type)
        {
            LogicalMethodInfo[] methodInfos = LogicalMethodInfo.Create(type.GetMethods(), LogicalMethodTypes.Sync);

            Hashtable formatterTypes = new Hashtable();

            for (int i = 0; i < methodInfos.Length; i++)
            {
                LogicalMethodInfo methodInfo = methodInfos[i];
                try {
                    object[] attributes = methodInfo.GetCustomAttributes(typeof(HttpMethodAttribute));
                    if (attributes.Length == 0)
                    {
                        continue;
                    }
                    HttpMethodAttribute attribute = (HttpMethodAttribute)attributes[0];
                    HttpClientMethod    method    = new HttpClientMethod();
                    method.readerType = attribute.ReturnFormatter;
                    method.writerType = attribute.ParameterFormatter;
                    method.methodInfo = methodInfo;
                    AddFormatter(formatterTypes, method.readerType, method);
                    AddFormatter(formatterTypes, method.writerType, method);
                    methods.Add(methodInfo.Name, method);
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    throw new InvalidOperationException(Res.GetString(Res.WebReflectionError, methodInfo.DeclaringType.FullName, methodInfo.Name), e);
                }
            }

            foreach (Type t in formatterTypes.Keys)
            {
                ArrayList           list = (ArrayList)formatterTypes[t];
                LogicalMethodInfo[] m    = new LogicalMethodInfo[list.Count];
                for (int j = 0; j < list.Count; j++)
                {
                    m[j] = ((HttpClientMethod)list[j]).methodInfo;
                }
                object[] initializers = MimeFormatter.GetInitializers(t, m);
                bool     isWriter     = typeof(MimeParameterWriter).IsAssignableFrom(t);
                for (int j = 0; j < list.Count; j++)
                {
                    if (isWriter)
                    {
                        ((HttpClientMethod)list[j]).writerInitializer = initializers[j];
                    }
                    else
                    {
                        ((HttpClientMethod)list[j]).readerInitializer = initializers[j];
                    }
                }
            }
        }
        public HttpSimpleMethodStubInfo(TypeStubInfo parent, LogicalMethodInfo source) : base(parent, source)
        {
            object[] atts = source.CustomAttributeProvider.GetCustomAttributes(typeof(HttpMethodAttribute), true);
            if (atts.Length > 0)
            {
                HttpMethodAttribute at = (HttpMethodAttribute)atts[0];
                ParameterWriterType = new MimeFormatterInfo(at.ParameterFormatter);
                ReturnReaderType    = new MimeFormatterInfo(at.ReturnFormatter);
            }

            if (ReturnReaderType == null)
            {
                if (source.IsVoid)
                {
                    ReturnReaderType = new MimeFormatterInfo(typeof(NopReturnReader));
                }
                else
                {
                    ReturnReaderType = new MimeFormatterInfo(typeof(XmlReturnReader));
                }
            }
        }