示例#1
0
        /// <summary>
        /// Determines the proper responce encoding, then applies it.
        /// </summary>
        /// <returns>
        /// Am encoded string, or null if the encoding needs to be BSON.
        /// </returns>
        /// <typeparam name="T">JSON        /// <summary>
        /// Constructor with message.
        /// </summary> serializable.</typeparam>
        /// <param name="query">Queries to read.</param>
        /// <param name="document">A document to be encoded.</param>
        public static string FulfilEncoding <T>(IQueryCollection query, T document)
        {
            if (query.As <bool>("bson"))
            {
                return(null);
            }

            string             json;
            JsonWriterSettings settings = new JsonWriterSettings();

            settings.OutputMode = JsonOutputMode.RelaxedExtendedJson;

            if (query.As <bool>("ugly"))
            {
                json = document.ToJson(settings);
                json = Regex.Replace(json, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
                return(json);
            }
            else
            {
                settings.Indent = true;
                return(document.ToJson(settings));
            }
        }
示例#2
0
 /// <summary>
 /// Determines the encoding of the request.
 /// </summary>
 /// <returns>
 /// True if there is a request for BSON encoding.
 /// </returns>
 /// <param name="query">Queries to read.</param>
 public static bool CheckDecoding(IQueryCollection query)
 {
     return(query.As <bool>("bson"));
 }