예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RestResource"/> class.
        /// </summary>
        /// <param name="type">The resource type.</param>
        /// <param name="headers">A collection of HTTP headers to pass to the request.</param>
        public RestResource(RestResourceType type, WebHeaderCollection headers)
        {
            if (!Enum.IsDefined(typeof(RestResourceType), type))
            {
                throw new ArgumentOutOfRangeException("type");
            }

            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            Type = type;
            Headers = headers;
        }
        /// <summary>
        /// Creates a serializer instance based on the object type and the REST resource type.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="xmlNamespace">An optional XML resource namespace.</param>
        /// <returns>The serializer instance.</returns>
        public virtual IRestClientSerializer Create(Type objectType, RestResourceType resourceType, string xmlNamespace)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }

            if (objectType == typeof(string))
            {
                return new StringClientSerializer();
            }

            switch (resourceType)
            {
                case RestResourceType.Json:
                    return new JsonClientSerializer();
                case RestResourceType.Xml:
                    return new XmlClientSerializer(xmlNamespace);
            }

            throw new NotSupportedException();
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RestResource"/> class.
 /// </summary>
 /// <param name="type">The resource type.</param>
 public RestResource(RestResourceType type) : this(type, new WebHeaderCollection())
 {
 }