public virtual void Export(object value, JsonWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (JsonNull.LogicallyEquals(value))
            {
                writer.WriteNull();
            }
            else
            {
                IExporter exporter = FindExporter(value.GetType());

                if (exporter != null)
                {
                    exporter.Export(this, value, writer);
                }
                else
                {
                    writer.WriteString(value.ToString());
                }
            }
        }
Example #2
0
        /// <summary>
        /// Writes a JSON array of JSON strings given an enumerable source
        /// of arbitrary <see cref="Object"/> values.
        /// </summary>

        public void WriteStringArray(IEnumerable values)
        {
            if (values == null)
            {
                WriteNull();
            }
            else
            {
                WriteStartArray();

                foreach (object value in values)
                {
                    if (JsonNull.LogicallyEquals(value))
                    {
                        WriteNull();
                    }
                    else
                    {
                        WriteString(value.ToString());
                    }
                }

                WriteEndArray();
            }
        }
Example #3
0
        /// <summary>
        /// Writes a JSON array of JSON strings given an array of
        /// <see cref="String"/> values.
        /// </summary>

        public void WriteStringArray(params string[] values)
        {
            if (values == null)
            {
                WriteNull();
            }
            else
            {
                WriteStartArray();

                foreach (string value in values)
                {
                    if (JsonNull.LogicallyEquals(value))
                    {
                        WriteNull();
                    }
                    else
                    {
                        WriteString(value);
                    }
                }

                WriteEndArray();
            }
        }
        protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
        {
            Debug.Assert(context != null);
            Debug.Assert(value != null);
            Debug.Assert(writer != null);

            if (_properties.Count == 0)
            {
                writer.WriteString(value.ToString());
            }
            else
            {
                ObjectReferenceTracker tracker = null;

                try
                {
                    writer.WriteStartObject();

                    foreach (PropertyDescriptor property in _properties)
                    {
                        object propertyValue = property.GetValue(value);

                        if (!JsonNull.LogicallyEquals(propertyValue))
                        {
                            writer.WriteMember(property.Name);

                            if (tracker == null)
                            {
                                //
                                // We are about to enter a deeper scope so
                                // start tracking the current object being
                                // exported. This will help to detect
                                // recursive references that may occur
                                // through this exporter deeper in the tree.
                                //

                                tracker = TrackObject(context, value);
                            }

                            context.Export(propertyValue, writer);
                        }
                    }

                    writer.WriteEndObject();
                }
                finally
                {
                    if (tracker != null)
                    {
                        tracker.Pop(value);
                    }
                }
            }
        }
        public virtual void Export(ExportContext context, object value, JsonWriter writer)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (JsonNull.LogicallyEquals(value))
            {
                writer.WriteNull();
            }
            else
            {
                ExportValue(context, value, writer);
            }
        }