Пример #1
0
        private void WriteJsonProperty(string propertyName, object json)
        {
            if (json != null)
            {
                string jsonString = null;

                using (var writer = new TextJsonWriter())
                {
                    JsonSerializer.Write(json, writer);
                    if (!writer.IsEmpty)
                    {
                        jsonString = writer.ToString();
                    }
                }

                if (!string.IsNullOrWhiteSpace(jsonString))
                {
                    if (_commaNeeded)
                    {
                        WriteComma();
                    }

                    WritePropertyName(propertyName);
                    WriteJsonString(jsonString);

                    _commaNeeded = true;
                }
            }
        }
Пример #2
0
 private void WriteJson(object json)
 {
     using (var writer = new TextJsonWriter())
     {
         JsonSerializer.Write(json, writer);
         WriteJsonString(writer.ToString());
     }
 }
Пример #3
0
        /// <summary>
        /// Serializes the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public static string Serialize(T value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            using (var writer = new TextJsonWriter())
            {
                Write(value, writer);
                return(writer.ToString());
            }
        }
Пример #4
0
        private void WriteJsonProperty(string propertyName, object json)
        {
            if (json != null)
            {
                string jsonString = null;

                using (var writer = new TextJsonWriter())
                {
                    JsonSerializer.Write(json, writer);
                    if (!writer.IsEmpty)
                    {
                        jsonString = writer.ToString();
                    }
                }

                if (!string.IsNullOrWhiteSpace(jsonString))
                {
                    if (_commaNeeded)
                    {
                        WriteComma();
                    }

                    WritePropertyName(propertyName);
                    WriteJsonString(jsonString);

                    _commaNeeded = true;
                }
            }
        }
Пример #5
0
 private void WriteJson(object json)
 {
     using (var writer = new TextJsonWriter())
     {
         JsonSerializer.Write(json, writer);
         WriteJsonString(writer.ToString());
     }            
 }