예제 #1
0
 public bool Equals(JsonWriterConfiguration other)
 {
     return
         (other.Indent == Indent &&
          other.UseTabForIndent == UseTabForIndent &&
          other.IndentChars == IndentChars &&
          other.IndentThreshold == IndentThreshold &&
          true);
 }
예제 #2
0
        public static string WriteObject(object obj,
                                         JsonWriterConfiguration config = null,
                                         bool indent          = false,
                                         bool useTabForIndent = false,
                                         int indentChars      = 4,
                                         int indentThreshold  = 3)
        {
            JsonWriter jsonWriter = null;

            if (config != null)
            {
                if (_dictInstances.ContainsKey(config) == false)
                {
                    jsonWriter = new JsonWriter(config);
                    _dictInstances.Add(config, jsonWriter);
                }
                else
                {
                    jsonWriter = _dictInstances[config];
                }

                return(jsonWriter.Write(obj));
            }

            foreach (KeyValuePair <JsonWriterConfiguration, JsonWriter> pair in _dictInstances)
            {
                if (
                    pair.Key.Indent == indent &&
                    pair.Key.UseTabForIndent == useTabForIndent &&
                    pair.Key.IndentChars == indentChars &&
                    pair.Key.IndentThreshold == indentThreshold &&
                    true)
                {
                    jsonWriter = pair.Value;
                    break;
                }
            }

            if (jsonWriter != null)
            {
                return(jsonWriter.Write(obj));
            }

            JsonWriterConfiguration jsonWriterConfiguration = new JsonWriterConfiguration(
                indent: indent,
                useTabForIndent: useTabForIndent,
                indentChars: indentChars,
                indentThreshold: indentThreshold);

            jsonWriter = new JsonWriter(jsonWriterConfiguration);
            _dictInstances.Add(jsonWriterConfiguration, jsonWriter);

            return(jsonWriter.Write(obj));
        }
예제 #3
0
 public JsonWriter(JsonWriterConfiguration config = null)
 {
     _config = config ?? new JsonWriterConfiguration();
 }