Permalink
Browse files

Fix long & DateTimeOffset issues, fix sourcelink crlf issues

  • Loading branch information...
devlead committed May 9, 2018
1 parent a149833 commit 726c05debc9bb8c4a3a57ff0aabd843d1b26aba0
Showing with 58 additions and 16 deletions.
  1. +1 −0 .gitattributes
  2. +1 −1 appveyor.yml
  3. +39 −11 src/LitJson/JsonData.cs
  4. +12 −0 src/LitJson/JsonMapper.cs
  5. +3 −3 src/LitJson/LitJSON.csproj
  6. +2 −1 test/JsonDataTest.cs
View
@@ -0,0 +1 @@
*.cs eol=lf
View
@@ -9,4 +9,4 @@ build_script:
test: off
init:
- git config --global core.autocrlf true
- git config --global core.autocrlf input
View
@@ -435,22 +435,27 @@ public JsonData (string str)
return data.inst_double;
}
public static explicit operator Int32 (JsonData data)
public static explicit operator Int32(JsonData data)
{
if (data.type != JsonType.Int)
throw new InvalidCastException (
if (data.type != JsonType.Int && data.type != JsonType.Long)
{
throw new InvalidCastException(
"Instance of JsonData doesn't hold an int");
}
return data.inst_int;
// cast may truncate data... but that's up to the user to consider
return data.type == JsonType.Int ? data.inst_int : (int)data.inst_long;
}
public static explicit operator Int64 (JsonData data)
public static explicit operator Int64(JsonData data)
{
if (data.type != JsonType.Long && data.type != JsonType.Int)
throw new InvalidCastException (
"Instance of JsonData doesn't hold an int");
{
throw new InvalidCastException(
"Instance of JsonData doesn't hold a long");
}
return (data.type == JsonType.Long) ? data.inst_long : data.inst_int;
return data.type == JsonType.Long ? data.inst_long : data.inst_int;
}
public static explicit operator String (JsonData data)
@@ -833,7 +838,14 @@ public bool Equals (JsonData x)
return false;
if (x.type != this.type)
return false;
{
// further check to see if this is a long to int comparison
if ((x.type != JsonType.Int && x.type != JsonType.Long)
|| (this.type != JsonType.Int && this.type != JsonType.Long))
{
return false;
}
}
switch (this.type) {
case JsonType.None:
@@ -849,10 +861,26 @@ public bool Equals (JsonData x)
return this.inst_string.Equals (x.inst_string);
case JsonType.Int:
return this.inst_int.Equals (x.inst_int);
{
if (x.IsLong)
{
if (x.inst_long < Int32.MinValue || x.inst_long > Int32.MaxValue)
return false;
return this.inst_int.Equals((int)x.inst_long);
}
return this.inst_int.Equals(x.inst_int);
}
case JsonType.Long:
return this.inst_long.Equals (x.inst_long);
{
if (x.IsInt)
{
if (this.inst_long < Int32.MinValue || this.inst_long > Int32.MaxValue)
return false;
return x.inst_int.Equals((int)this.inst_long);
}
return this.inst_long.Equals(x.inst_long);
}
case JsonType.Double:
return this.inst_double.Equals (x.inst_double);
View
@@ -621,6 +621,12 @@ private static void RegisterBaseImporters ()
RegisterImporter (base_importers_table, typeof (int),
typeof (ulong), importer);
importer = delegate (object input) {
return Convert.ToInt64((int)input);
};
RegisterImporter(base_importers_table, typeof(int),
typeof(long), importer);
importer = delegate (object input) {
return Convert.ToSByte ((int) input);
};
@@ -681,6 +687,12 @@ private static void RegisterBaseImporters ()
};
RegisterImporter (base_importers_table, typeof (string),
typeof (DateTime), importer);
importer = delegate (object input) {
return DateTimeOffset.Parse((string)input, datetime_format);
};
RegisterImporter(base_importers_table, typeof(string),
typeof(DateTimeOffset), importer);
}
private static void RegisterImporter (
@@ -11,9 +11,9 @@
</PropertyGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<PackageReference Include="SourceLink.Create.GitHub" Version="2.7.6" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.7.6" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.7.6" />
<PackageReference Include="SourceLink.Create.GitHub" Version="2.8.1" PrivateAssets="All" />
<DotNetCliToolReference Include="dotnet-sourcelink-git" Version="2.8.1" />
<DotNetCliToolReference Include="dotnet-sourcelink" Version="2.8.1" />
</ItemGroup>
<PropertyGroup>
View
@@ -147,8 +147,9 @@ public void EqualsTest ()
b = 10L;
Assert.IsTrue (a.Equals (b), "A4");
// Int now comparable to long
b = 10;
Assert.IsFalse (a.Equals (b), "A5");
Assert.IsTrue (a.Equals (b), "A5");
b = 11L;
Assert.IsFalse (a.Equals (b), "A6");

0 comments on commit 726c05d

Please sign in to comment.