/// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="context">Context for the writer.</param>
        /// <param name="writer"><see cref="TextWriter"/> to receive the output.</param>
        public FudgeJSONStreamWriter(FudgeContext context, TextWriter writer)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (writer == null)
                throw new ArgumentNullException("writer");

            this.context = context;
            this.writer = writer;
            this.settings = (JSONSettings)context.GetProperty(JSONSettings.JSONSettingsProperty) ?? new JSONSettings();
        }
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="context">Context for the writer.</param>
        /// <param name="settings">Settings for the writer (rather than getting from the context).</param>
        /// <param name="writer"><see cref="TextWriter"/> to receive the output.</param>
        public FudgeJSONStreamWriter(FudgeContext context, JSONSettings settings, TextWriter writer)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (writer == null)
                throw new ArgumentNullException("writer");
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.context = context;
            this.writer = writer;
            this.settings = settings;
        }
        /// <summary>
        /// Constructs a <see cref="FudgeJSONStreamReader"/> on a given <see cref="TextReader"/>.
        /// </summary>
        /// <param name="context">Context to control behaviours.</param>
        /// <param name="settings">Settings to override any in the <see cref="FudgeContext"/>.</param>
        /// <param name="reader"><see cref="TextReader"/> providing the data.</param>
        public FudgeJSONStreamReader(FudgeContext context, JSONSettings settings, TextReader reader)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (reader == null)
                throw new ArgumentNullException("reader");
            if (settings == null)
                throw new ArgumentNullException("settings");

            this.context = context;
            this.reader = reader;
            this.settings = settings;
        }
Beispiel #4
0
 /// <summary>
 /// Clones an existing settings object.
 /// </summary>
 /// <param name="other">Object to clone</param>
 public JSONSettings(JSONSettings other)
 {
 }
 /// <summary>
 /// Constructs a <see cref="FudgeJSONStreamReader"/> using a <c>string</c> for the underlying data.
 /// </summary>
 /// <param name="context">Context to control behaviours.</param>
 /// <param name="settings">Settings to override any in the <see cref="FudgeContext"/>.</param>
 /// <param name="text">Text containing JSON message.</param>
 /// <example>This example shows a simple JSON string being converted into a <see cref="FudgeMsg"/> object:
 /// <code>
 /// string json = @"{""name"" : ""fred""}";
 /// FudgeMsg msg = new FudgeJSONStreamReader(json).ReadToMsg();
 /// </code>
 /// </example>
 public FudgeJSONStreamReader(FudgeContext context, JSONSettings settings, string text)
     : this(context, settings, new StringReader(text))
 {
 }
        public void FieldNamesAndOrdinalsLogic_FRN86()
        {
            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);

            var msg = context.NewMessage(new Field(1, "ord"),
                                         new Field("A", "name"),
                                         new Field("B", 2, "name and ord"),
                                         new Field(null, null, "empty"));
            writer.WriteMsg(msg);
            AssertEqualsNoWhiteSpace("{\"1\" : \"ord\", \"A\" : \"name\", \"B\" : \"name and ord\", \"\" : \"empty\"}", stringWriter.ToString());

            // Now try it preferring ordinals to names
            var stringWriter2 = new StringWriter();
            var settings = new JSONSettings() { PreferFieldNames = false };
            var writer2 = new FudgeJSONStreamWriter(context, settings, stringWriter2);
            writer2.WriteMsg(msg);
            AssertEqualsNoWhiteSpace("{\"1\" : \"ord\", \"A\" : \"name\", \"2\" : \"name and ord\", \"\" : \"empty\"}", stringWriter2.ToString());
        }