/// <summary>
        /// Create the response.
        /// </summary>
        /// <typeparam name="T">The body type.</typeparam>
        /// <param name="response">The response.</param>
        /// <param name="data">The body type data.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns>The string response.</returns>
        /// <exception cref="System.Exception"></exception>
        public static string Response <T>(WebResponse response, T data, NameValueCollection queryString)
        {
            string responseData = "";

            // If the data format key query exists.
            if (queryString[DataFormatQueryStringKey] != null)
            {
                // Select the data format.
                switch (queryString[DataFormatQueryStringKey].ToLower())
                {
                case "xml":
                    // Serialise the data.
                    WebResponse <T> webResponse = new WebResponse <T>();
                    webResponse.ExplicitAssignment(response, data);

                    // Serialise the response data.
                    responseData = ResponseSerialiseAction <WebResponse <T> >(webResponse, queryString);
                    break;

                case "json":
                    // Json data format.
                    responseData = JavaObjectNotation.JavaScriptSerializer(response);
                    break;

                case "query":
                default:
                    // Query data format.
                    NameValueCollection col = Nequeo.Serialisation.NameValue.Serializer <WebResponse>(response);
                    responseData = Nequeo.Web.WebManager.CreateQueryString(col).Replace("body=", "");
                    break;
                }
            }
            else
            {
                // Query data format.
                NameValueCollection col = Nequeo.Serialisation.NameValue.Serializer <WebResponse>(response);
                responseData = Nequeo.Web.WebManager.CreateQueryString(col).Replace("body=", "");
            }

            // Return the body data.
            return(responseData);
        }
        /// <summary>
        /// Get the response body.
        /// </summary>
        /// <typeparam name="T">The body type.</typeparam>
        /// <param name="data">The body data.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns>The body</returns>
        /// <exception cref="System.Exception"></exception>
        public static string ResponseBody <T>(T data, NameValueCollection queryString)
        {
            string responseBody = "";

            // If the data format key query exists.
            if (queryString[DataFormatQueryStringKey] != null)
            {
                // Select the data format.
                switch (queryString[DataFormatQueryStringKey].ToLower())
                {
                case "xml":
                    // Serialise the data.
                    responseBody = ResponseSerialiseAction <T>(data, queryString);
                    break;

                case "json":
                    // Json data format.
                    responseBody = JavaObjectNotation.JavaScriptSerializer(data);
                    break;

                case "query":
                default:
                    // Query data format.
                    NameValueCollection col = Nequeo.Serialisation.NameValue.Serializer <T>(data);
                    responseBody = Nequeo.Web.WebManager.CreateQueryString(col);
                    break;
                }
            }
            else
            {
                // Query data format.
                NameValueCollection col = Nequeo.Serialisation.NameValue.Serializer <T>(data);
                responseBody = Nequeo.Web.WebManager.CreateQueryString(col);
            }

            // Return the body data.
            return(responseBody);
        }
Exemple #3
0
 /// <summary>
 /// Serialise the current object type.
 /// </summary>
 /// <typeparam name="T">The type to examine.</typeparam>
 /// <param name="source">The current source object type.</param>
 /// <returns>The string of serialised data.</returns>
 public static string SerialiseJson <T>(this T source)
 {
     return(JavaObjectNotation.JavaScriptSerializer(source));
 }