/// <summary>
 /// Returns the content of request body as is. Ignores the ContentType parameter.
 /// The request body must be pre formatted into desired content type by the user of this class.
 /// </summary>
 /// <param name="contentType">Ignored</param>
 /// <returns></returns>
 public override string ToString(ContentType contentType)
 {
     //Plain text body should already be in the string serialized form.
     //So, default logic to convert to string needs to be overriden.
     return (string)Content;
 }
 public override byte[] ToByteArray(ContentType contentType)
 {
     //Plain text body should already be in the string serialized form.
     //So, default logic to convert to string needs to be overriden.
     return (byte[])Content;
 }
Example #3
0
 /// <summary>
 /// Converts the request body into array of bytes(byte[]).
 /// </summary>
 /// <param name="contentType">The content type (MIME type) into which the request body must be serialized.</param>
 /// <returns>Binary representation of request body that can directly be written into the request stream.</returns>
 public virtual byte[] ToByteArray(ContentType contentType)
 {
     //c# strings are UTF8 encoded
     return Encoding.UTF8.GetBytes(ToString(contentType));
 }
 public override string ToString(ContentType contentType)
 {
     //A raw binary data can be represented into ASCII string in most of the system.
     return Encoding.ASCII.GetString((byte[])Content);
 }
Example #5
0
 /// <summary>
 /// Serialize the content into string using the serializer registerd for given content type.
 /// </summary>
 /// <param name="contentType">The content type (MIME type) into which the request body must be serialized.</param>
 /// <returns>String representation of the request body, formatted into the provided content type.</returns>
 public virtual string ToString(ContentType contentType)
 {
     var serializer = RestConfiguration.Serializers.GetSerializer(contentType.ToString());
     return serializer.Serialize(this);
 }