Пример #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();
		}
Пример #2
0
		private void WriteMemberInfoProperty(JsonWriter writer, object value, MemberInfo member, string propertyName) {
			if (!ReflectionUtils.IsIndexedProperty(member)) {
				object memberValue = ReflectionUtils.GetMemberValue(member, value);

				if (writer.SerializeStack.IndexOf(memberValue) != -1) {
					switch (_referenceLoopHandling) {
						case ReferenceLoopHandling.Error:
							throw new JsonSerializationException("Self referencing loop");
						case ReferenceLoopHandling.Ignore:
							// return from method
							return;
						case ReferenceLoopHandling.Serialize:
							// continue
							break;
						default:
							throw new InvalidOperationException(string.Format("Unexpected ReferenceLoopHandling value: '{0}'", _referenceLoopHandling));
					}
				}

				writer.WritePropertyName(propertyName != null ? propertyName : member.Name);
				SerializeValue(writer, memberValue);
			}
		}