コード例 #1
0
        public static IDictionary <string, object> AddRangeExtension(IFieldFacade field, IDictionary <string, object> customExtensions)
        {
            var range = field.Range;

            if (range != null)
            {
                customExtensions = customExtensions ?? new Dictionary <string, object>();

                var propertyType = field.Specification.GetUnderlyingType();

                object min;
                object max;

                if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
                {
                    var minDays = (double)range.Item1.ToType(typeof(double), null);
                    var maxDays = (double)range.Item2.ToType(typeof(double), null);

                    DateTime earliest = DateTime.Today.AddDays(minDays);
                    DateTime latest   = DateTime.Today.AddDays(maxDays);

                    min = ToDateFormatString(earliest);
                    max = ToDateFormatString(latest);
                }
                else
                {
                    min = range.Item1.ToType(propertyType, null);
                    max = range.Item2.ToType(propertyType, null);
                }

                OptionalProperty[] op  = { new OptionalProperty("min", min), new OptionalProperty("max", max) };
                MapRepresentation  map = MapRepresentation.Create(op);
                customExtensions[JsonPropertyNames.CustomRange] = map;
            }
            return(customExtensions);
        }
コード例 #2
0
        public static IDictionary<string, object> AddRangeExtension(IFieldFacade field, IDictionary<string, object> customExtensions ) {
            var range = field.Range;

            if (range != null) {
                customExtensions = customExtensions ?? new Dictionary<string, object>();

                var propertyType = field.Specification.GetUnderlyingType();

                object min;
                object max;

                if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) {
                    var minDays = (double)range.Item1.ToType(typeof(double), null);
                    var maxDays = (double)range.Item2.ToType(typeof(double), null);

                    DateTime earliest = DateTime.Today.AddDays(minDays);
                    DateTime latest = DateTime.Today.AddDays(maxDays);

                    min = ToDateFormatString(earliest);
                    max = ToDateFormatString(latest);
                }
                else {
                    min = range.Item1.ToType(propertyType, null);
                    max = range.Item2.ToType(propertyType, null);
                }

                OptionalProperty[] op = { new OptionalProperty("min", min), new OptionalProperty("max", max) };
                MapRepresentation map = MapRepresentation.Create(op);
                customExtensions[JsonPropertyNames.CustomRange] = map;
            }
            return customExtensions;
        }