private static void WriteJsonProperties( JsonWriter writer, DynamicTableEntity entity, List <string> excludedProperties = null) { if (entity == null) { return; } writer.WritePropertyName("PartitionKey"); writer.WriteValue(entity.PartitionKey); writer.WritePropertyName("RowKey"); writer.WriteValue(entity.RowKey); writer.WritePropertyName("Timestamp"); writer.WriteValue(entity.Timestamp); writer.WritePropertyName("ETag"); writer.WriteValue(entity.ETag); using (IEnumerator <KeyValuePair <string, EntityProperty> > enumerator = (excludedProperties == null ? (IEnumerable <KeyValuePair <string, EntityProperty> >)entity.Properties : ((IEnumerable <KeyValuePair <string, EntityProperty> >)entity.Properties).Where <KeyValuePair <string, EntityProperty> >((Func <KeyValuePair <string, EntityProperty>, bool>)(p => !excludedProperties.Contains(p.Key)))).GetEnumerator()) { while (((IEnumerator)enumerator).MoveNext()) { KeyValuePair <string, EntityProperty> current = enumerator.Current; DynamicTableEntityJsonConverter.WriteJsonProperty(writer, current); } } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (value == null) { return; } writer.WriteStartObject(); DynamicTableEntityJsonConverter.WriteJsonProperties(writer, (DynamicTableEntity)value, this.excludedProperties); writer.WriteEndObject(); }
private static void WriteJsonProperty( JsonWriter writer, KeyValuePair <string, EntityProperty> property) { //https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_JsonToken.htm if (string.IsNullOrWhiteSpace(property.Key) || property.Value == null) { return; } switch ((int)property.Value.PropertyType) { case 0: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.StringValue, property.Value.PropertyType); break; case 1: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.BinaryValue, property.Value.PropertyType); break; case 2: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.BooleanValue, property.Value.PropertyType); break; case 3: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.DateTimeOffsetValue, property.Value.PropertyType); break; case 4: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.DoubleValue, property.Value.PropertyType); break; case 5: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.GuidValue, property.Value.PropertyType); break; case 6: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.Int32Value, property.Value.PropertyType); break; case 7: DynamicTableEntityJsonConverter.WriteJsonPropertyWithEdmType(writer, property.Key, (object)property.Value.Int64Value, property.Value.PropertyType); break; default: throw new NotSupportedException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Unsupported EntityProperty.PropertyType:{0} detected during serialization.", (object)property.Value.PropertyType)); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { return((object)null); } DynamicTableEntity dynamicTableEntity = new DynamicTableEntity(); using (List <JProperty> .Enumerator enumerator = JObject.Load(reader).Properties().ToList <JProperty>().GetEnumerator()) { while (enumerator.MoveNext()) { JProperty current = enumerator.Current; if (string.Equals(current.Name, "PartitionKey", StringComparison.Ordinal)) { dynamicTableEntity.PartitionKey = ((object)current.Value).ToString(); } else if (string.Equals(current.Name, "RowKey", StringComparison.Ordinal)) { dynamicTableEntity.RowKey = ((object)current.Value).ToString(); } else if (string.Equals(current.Name, "Timestamp", StringComparison.Ordinal)) { dynamicTableEntity.Timestamp = (DateTimeOffset)current.Value.ToObject <DateTimeOffset>(serializer); } else if (string.Equals(current.Name, "ETag", StringComparison.Ordinal)) { dynamicTableEntity.ETag = (((object)current.Value).ToString()); } else { EntityProperty entityProperty = DynamicTableEntityJsonConverter.CreateEntityProperty(serializer, current); dynamicTableEntity.Properties.Add(current.Name, entityProperty); } } } return((object)dynamicTableEntity); }
public DynamicTableEntityJsonSerializer(List <string> excludedProperties = null) { this.jsonConverter = new DynamicTableEntityJsonConverter(excludedProperties); }