Exemple #1
0
 private static void WritePhoneNumber(JsonWriter writer, string location, string number)
 {
     writer.WriteStartObject();      //  {
     writer.WriteMember("Location"); //      "Location" : 
     writer.WriteString(location);   //          "...", 
     writer.WriteMember("Number");   //      "Number" :
     writer.WriteString(number);     //          "..."
     writer.WriteEndObject();        //  }
 }
        public virtual void Format(JsonWriter writer)
        {
            writer.WriteStartObject();
            
            foreach (string name in _nameIndexList)
            {
                writer.WriteMember(name);    
                writer.WriteValue(InnerHashtable[name]);
            }

            writer.WriteEndObject();
        }
        public void Export(JsonWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            writer.WriteStartObject();
            
            foreach (string name in NameIndexList)
            {
                writer.WriteMember(name);    
                writer.WriteValue(InnerHashtable[name]);
            }

            writer.WriteEndObject();
        }
Exemple #4
0
 private static void WriteRssToJson(Item item, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteMember("title");
     writer.WriteString(item.title);
     writer.WriteMember("description");
     writer.WriteString(item.description);
     writer.WriteMember("link");
     writer.WriteString(item.link);
     writer.WriteEndObject();
 }
Exemple #5
0
 private static void WriteRssToJson(Channel channel, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteMember("title");
     writer.WriteString(channel.title);
     writer.WriteMember("link");
     writer.WriteString(channel.link);
     writer.WriteMember("items");
     writer.WriteStartArray();
     foreach (Item item in channel.item)
         WriteRssToJson(item, writer);
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
Exemple #6
0
 //
 // NOTE: For sake of brevity, the following WriteRss* methods do not
 // write out all the members of the RichSiteSummary and related types.
 //
 private static void WriteRssToJson(RichSiteSummary rss, JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteMember("version");
     writer.WriteString(rss.version);
     writer.WriteMember("channel");
     WriteRssToJson(rss.channel, writer);
     writer.WriteEndObject();
 }
Exemple #7
0
        protected virtual void Export(ExportContext context, JsonWriter writer)
        {
            if (context == null)
                throw new ArgumentNullException("context");

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

            writer.WriteStartObject();
            
            foreach (string name in NameIndexList)
            {
                writer.WriteMember(name);    
                context.Export(InnerHashtable[name], writer);
            }

            writer.WriteEndObject();
        }
     protected virtual void FormatDictionary(IDictionary dictionary, JsonWriter writer)
     {
         writer.WriteStartObject();
 
         foreach (DictionaryEntry entry in dictionary)
         {
             writer.WriteMember(entry.Key.ToString());
             writer.WriteValue(entry.Value);
         }
 
         writer.WriteEndObject();
     }
 public void DepthIncreasesInsideObject()
 {
     _writer.WriteStartObject();
     Assert.AreEqual(1, _writer.Depth);
     _writer.WriteMember(string.Empty);
     _writer.WriteStartObject();
     Assert.AreEqual(2, _writer.Depth);
     _writer.WriteEndObject();
     Assert.AreEqual(1, _writer.Depth);
     _writer.WriteEndObject();
     Assert.AreEqual(0, _writer.Depth);
 }
        /// <summary>
        /// The export.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="writer">
        /// The writer.
        /// </param>
        public void Export(ExportContext context, object value, JsonWriter writer)
        {
            writer.WriteStartObject();
            writer.WriteMember("Critter");

            var critter = (Critter)value;
            writer.WriteStartObject();

            if (exportType > ExportType.Expanded)
            {
                writer.WriteMember("Age");
                writer.WriteNumber(critter.Age);
                writer.WriteMember("N");
                writer.WriteNumber(critter.N);
            }

            writer.WriteMember("Rank");
            writer.WriteNumber(critter.Rank);

            writer.WriteMember("Fitness");
            writer.WriteStartObject();
            int i = 0;
            foreach (var n in Enum.GetNames(typeof(FitnessParameter)))
            {
                writer.WriteMember(n);
                writer.WriteNumber(critter.Fitness[i++]);
            }

            writer.WriteEndObject();

            // writer.WriteMember("Fitness");
            // context.Export(critter.Fitness,writer);
            if (exportType > ExportType.Summary)
            {
                writer.WriteMember("Route");
                writer.WriteStartArray();
                foreach (var node in critter.Route)
                {
                    writer.WriteNumber(node.Node.Id);
                }
                writer.WriteEndArray();
            }

            writer.WriteMember("Legs");
            writer.WriteStartArray();
            foreach (var leg in critter.Fitness.JourneyLegs)
            {
                writer.WriteStartObject();

                if (exportType > ExportType.Summary)
                {
                    writer.WriteMember("Start");
                    writer.WriteNumber(leg.Origin.Id);
                    writer.WriteMember("End");
                    writer.WriteNumber(leg.Destination.Id);
                    writer.WriteMember("Route");
                    writer.WriteString(leg.RouteId1);
                }

                if (exportType > ExportType.Simple)
                {
                    writer.WriteMember("StartLocation");
                    writer.WriteStartObject();
                    writer.WriteMember("Lat");
                    writer.WriteNumber(leg.Origin.Latitude);
                    writer.WriteMember("Long");
                    writer.WriteNumber(leg.Origin.Longitude);

                    writer.WriteEndObject();

                    writer.WriteMember("EndLocation");
                    writer.WriteStartObject();
                    writer.WriteMember("Lat");
                    writer.WriteNumber(leg.Destination.Latitude);
                    writer.WriteMember("Long");
                    writer.WriteNumber(leg.Destination.Longitude);
                    writer.WriteEndObject();
                }

                writer.WriteMember("Mode");
                writer.WriteString(leg.TransportMode.ToString());
                writer.WriteMember("TotalTime");
                context.Export(leg.TotalTime, writer);
                writer.WriteMember("DepartTime");
                context.Export(leg.DepartureTime, writer);
                writer.WriteMember("OriginName");
                writer.WriteString(leg.Origin.StopSpecName);

                writer.WriteEndObject();
            }

            writer.WriteEndArray();

            writer.WriteEndObject();
            writer.WriteEndObject();
        }