-Added JSON Schema implementation
-Move test serialization objects to TestObjects namespace -Fixed JsonConvert to always write a floating point number with a decimal place -Changed Type values to serialize and deserialize to type name string -Fixed JsonWriter to allow objects and arrays to be written in a constructor -Added JsonContainerAttribute with Id, Title and Description members. JsonObject and JsonArray inherit from this attribute -Added JsonArrayAttribute. Has flag to control whether array can contain null items. -Added IsRequired to JsonProperty -Replaced protected method GetSerializableMembers with GetMemberMappings on JsonSerializer -Fixed QuoteChar not getting set when parsing property name -Added Load(JsonReader) to JProperty, JConstructor -Fixed error when populating JProperty with content from collection -Added the ability for JsonTokenWriter to write individual values as well as arrays and objects -Added CreateReader to JToken -Added FromObject to JToken -Added ReadFrom to JToken
This commit is contained in:
@@ -56,5 +56,62 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
return (char)((n - 10) + 97);
|
||||
}
|
||||
|
||||
public static int GetDecimalPlaces(double value)
|
||||
{
|
||||
// increasing max decimal places above 10 produces weirdness
|
||||
int maxDecimalPlaces = 10;
|
||||
double threshold = Math.Pow(0.1d, maxDecimalPlaces);
|
||||
|
||||
if (value == 0.0)
|
||||
return 0;
|
||||
int decimalPlaces = 0;
|
||||
while (value - Math.Floor(value) > threshold && decimalPlaces < maxDecimalPlaces)
|
||||
{
|
||||
value *= 10.0;
|
||||
decimalPlaces++;
|
||||
}
|
||||
return decimalPlaces;
|
||||
}
|
||||
|
||||
public static int? Min(int? val1, int? val2)
|
||||
{
|
||||
if (val1 == null)
|
||||
return val2;
|
||||
if (val2 == null)
|
||||
return val1;
|
||||
|
||||
return Math.Min(val1.Value, val2.Value);
|
||||
}
|
||||
|
||||
public static int? Max(int? val1, int? val2)
|
||||
{
|
||||
if (val1 == null)
|
||||
return val2;
|
||||
if (val2 == null)
|
||||
return val1;
|
||||
|
||||
return Math.Max(val1.Value, val2.Value);
|
||||
}
|
||||
|
||||
public static double? Min(double? val1, double? val2)
|
||||
{
|
||||
if (val1 == null)
|
||||
return val2;
|
||||
if (val2 == null)
|
||||
return val1;
|
||||
|
||||
return Math.Min(val1.Value, val2.Value);
|
||||
}
|
||||
|
||||
public static double? Max(double? val1, double? val2)
|
||||
{
|
||||
if (val1 == null)
|
||||
return val2;
|
||||
if (val2 == null)
|
||||
return val1;
|
||||
|
||||
return Math.Max(val1.Value, val2.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user