Exemple #1
0
		private void SerializeDictionary(JsonWriter writer, IDictionary values)
		{
			writer.WriteStartObject();

			foreach (DictionaryEntry entry in values)
			{
				writer.WritePropertyName(entry.Key.ToString());
				SerializeValue(writer, entry.Value);
			}

			writer.WriteEndObject();
		}
Exemple #2
0
		private void SerializeObject(JsonWriter writer, object value)
		{
			Type objectType = value.GetType();

			TypeConverter converter = TypeDescriptor.GetConverter(objectType);

			// use the objectType's TypeConverter if it has one and can convert to a string
			if (converter != null && !(converter is ComponentConverter) && converter.GetType() != typeof(TypeConverter))
			{
				if (converter.CanConvertTo(typeof(string)))
				{
					writer.WriteValue(converter.ConvertToInvariantString(value));
					return;
				}
			}

			writer.SerializeStack.Add(value);

			writer.WriteStartObject();

			MemberMappingCollection memberMappings = GetMemberMappings(objectType);

			foreach (MemberMapping memberMapping in memberMappings)
			{
				if (!memberMapping.Ignored && memberMapping.Readable)
					WriteMemberInfoProperty(writer, value, memberMapping.Member, memberMapping.MappingName);
			}

			writer.WriteEndObject();

			writer.SerializeStack.Remove(value);
		}