Пример #1
0
        private static object PopulateConfigurationJsonSerializer(JsonBinder binder, object value, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values)
        {
            var config = new ConfigurationBuilder();

            config.AddInMemoryCollection(values);
            return(binder.Populate(value, config.Build(), serializer));
        }
Пример #2
0
 private static object PopulateJsonSerializer(JsonBinder binder, object value, JsonSerializer serializer, IEnumerable <KeyValuePair <string, string> > values)
 {
     return(binder.Populate(value, values, serializer));
 }
Пример #3
0
        void ITableEntity.ReadEntity(IDictionary <string, EntityProperty> properties, OperationContext operationContext)
        {
            var getter = getPropertyGetter(GetType());

            _binder.Populate(this, properties
                             .Select(x =>
            {
                var value = x.Value.PropertyAsObject?.ToString();
                if (x.Value.PropertyType != EdmType.DateTime)
                {
                    return(new KeyValuePair <string, string>(x.Key, value));
                }

                if (x.Value.DateTimeOffsetValue.HasValue)
                {
                    if (TryGetPropertyType(getter, GetType(), x.Key, out var propertyType))
                    {
                        if (propertyType == typeof(Instant))
                        {
                            value = InstantPattern.ExtendedIso.Format(
                                Instant.FromDateTimeOffset(x.Value.DateTimeOffsetValue.Value));
                        }
                        else if (propertyType == typeof(OffsetDateTime))
                        {
                            value = OffsetDateTimePattern.Rfc3339.Format(
                                OffsetDateTime.FromDateTimeOffset(x.Value.DateTimeOffsetValue.Value));
                        }
                        else if (propertyType == typeof(ZonedDateTime))
                        {
                            value = CustomNodaConverters.ZonedDateTimeFormatter.Format(
                                ZonedDateTime.FromDateTimeOffset(x.Value.DateTimeOffsetValue.Value));
                        }
                        else if (propertyType == typeof(LocalDateTime))
                        {
                            value = LocalDateTimePattern.ExtendedIso.Format(
                                LocalDateTime.FromDateTime(x.Value.DateTimeOffsetValue.Value.DateTime));
                        }
                        else if (propertyType == typeof(LocalDate))
                        {
                            value = LocalDatePattern.Iso.Format(
                                LocalDate.FromDateTime(x.Value.DateTimeOffsetValue.Value.DateTime));
                        }
                        else
                        {
                            value = x.Value.DateTimeOffsetValue.Value.ToString("O");
                        }
                    }
                    else
                    {
                        value = x.Value.DateTimeOffsetValue.Value.ToString("O");
                    }
                }

                if (x.Value.DateTime.HasValue)
                {
                    if (TryGetPropertyType(getter, GetType(), x.Key, out var propertyType))
                    {
                        if (propertyType == typeof(LocalDateTime))
                        {
                            value = LocalDateTimePattern.ExtendedIso.Format(
                                LocalDateTime.FromDateTime(x.Value.DateTime.Value));
                        }
                        else if (propertyType == typeof(LocalDate))
                        {
                            value = LocalDatePattern.Iso.Format(LocalDate.FromDateTime(x.Value.DateTime.Value));
                        }
                        else
                        {
                            value = x.Value.DateTime.Value.ToString("O");
                        }
                    }
                    else
                    {
                        value = x.Value.DateTime.Value.ToString("O");
                    }
                }
                return(new KeyValuePair <string, string>(x.Key, value));
            }));
        }