private bool SerializeObjectProperties(ObjectReflectionCache.ObjectPropertyList objectPropertyList, StringBuilder destination, JsonSerializeOptions options, SingleItemOptimizedHashSet <object> objectsInPath, int depth) { destination.Append('{'); bool first = true; foreach (var propertyValue in objectPropertyList) { var originalLength = destination.Length; try { if (HasNameAndValue(propertyValue)) { if (!first) { destination.Append(", "); } if (options.QuoteKeys) { QuoteValue(destination, propertyValue.Name); } else { destination.Append(propertyValue.Name); } destination.Append(':'); var objTypeCode = propertyValue.TypeCode; if (objTypeCode != TypeCode.Object) { SerializeSimpleTypeCodeValue((IConvertible)propertyValue.Value, objTypeCode, destination, options); first = false; } else { if (!SerializeObject(propertyValue.Value, destination, options, objectsInPath, depth + 1)) { destination.Length = originalLength; } else { first = false; } } } } catch { // skip single property destination.Length = originalLength; } } destination.Append('}'); return(true); }
private bool SerializeObjectProperties(ObjectReflectionCache.ObjectPropertyList objectPropertyList, StringBuilder destination, JsonSerializeOptions options, SingleItemOptimizedHashSet <object> objectsInPath, int depth) { if (objectPropertyList.Count == 0) { //no props return(SerializeObjectAsString(objectPropertyList.ToString(), TypeCode.Object, destination, options)); } destination.Append('{'); bool first = true; foreach (var propertyValue in objectPropertyList) { var originalLength = destination.Length; try { if (HasNameAndValue(propertyValue)) { if (!first) { destination.Append(", "); } if (options.QuoteKeys) { QuoteValue(destination, propertyValue.Name); } else { destination.Append(propertyValue.Name); } destination.Append(':'); if (!SerializeObject(propertyValue.Value, propertyValue.TypeCode, destination, options, objectsInPath, depth + 1)) { destination.Length = originalLength; } else { first = false; } } } catch { //skip this property destination.Length = originalLength; } } destination.Append('}'); return(true); }