Skip to content

Commit 4ffcd30

Browse files
committed
Support for .NET 3.5 and up.
1 parent 4d16099 commit 4ffcd30

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

src/JsonLD/JsonLD.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<FileAlignment>512</FileAlignment>
1414
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\JsonLD\</SolutionDir>
1515
<RestorePackages>true</RestorePackages>
16+
<TargetFrameworkProfile>
17+
</TargetFrameworkProfile>
1618
</PropertyGroup>
1719
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1820
<DebugSymbols>true</DebugSymbols>
@@ -22,6 +24,8 @@
2224
<DefineConstants>DEBUG;TRACE</DefineConstants>
2325
<ErrorReport>prompt</ErrorReport>
2426
<WarningLevel>4</WarningLevel>
27+
<UseVSHostingProcess>true</UseVSHostingProcess>
28+
<Prefer32Bit>false</Prefer32Bit>
2529
</PropertyGroup>
2630
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2731
<DebugType>pdbonly</DebugType>
@@ -30,6 +34,7 @@
3034
<DefineConstants>TRACE</DefineConstants>
3135
<ErrorReport>prompt</ErrorReport>
3236
<WarningLevel>4</WarningLevel>
37+
<Prefer32Bit>false</Prefer32Bit>
3338
</PropertyGroup>
3439
<ItemGroup>
3540
<Reference Include="Newtonsoft.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">

src/JsonLD/Util/JSONUtils.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using JsonLD.Util;
55
using Newtonsoft.Json;
66
using System.Net;
7-
using System.Threading.Tasks;
87
using Newtonsoft.Json.Linq;
98

109
namespace JsonLD.Util

src/JsonLD/Util/JavaCompat.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Security.Cryptography;
88
using System.Text;
99
using System.Text.RegularExpressions;
10-
using System.Threading.Tasks;
1110

1211
namespace JsonLD
1312
{
@@ -158,6 +157,14 @@ public static void Reverse<T>(this IList<T> list)
158157
}
159158
}
160159

160+
class JTokenStringCompare : Comparer<JToken>
161+
{
162+
public override int Compare(JToken x, JToken y)
163+
{
164+
return string.Compare((string)x, (string)y);
165+
}
166+
}
167+
161168
public static void SortInPlace<T>(this IList<T> list)
162169
{
163170
if (list is List<T>)
@@ -168,8 +175,10 @@ public static void SortInPlace<T>(this IList<T> list)
168175
{
169176
// TODO(sblom): This is really awful; figure out how to really sort a JArray in place.
170177
JArray arr = (JArray)list;
171-
var tmp = new List<JToken>((JArray)list);
172-
tmp.Sort(Comparer<JToken>.Create((s,t) => string.Compare((string)s,(string)t)));
178+
// .Select(x => x) is a workaround for .NET 3.5's List constructor's failure to
179+
// disbelieve Newtonsoft.Json when IJCollection.Count returns 0.
180+
List<JToken> tmp = arr.Select(x => x).ToList();
181+
tmp.Sort(new JTokenStringCompare());
173182
arr.RemoveAll();
174183
foreach (var t in tmp)
175184
{
@@ -193,7 +202,9 @@ public static void SortInPlace<T>(this IList<T> list, IComparer<T> cmp)
193202
// TODO(sblom): This is really awful; figure out how to really sort a JArray in place.
194203
JArray arr = (JArray)list;
195204
IComparer<JToken> comparer = (IComparer<JToken>)cmp;
196-
var tmp = new List<JToken>((JArray)list);
205+
// .Select(x => x) is a workaround for .NET 3.5's List constructor's failure to
206+
// disbelieve Newtonsoft.Json when IJCollection.Count returns 0.
207+
var tmp = arr.Select(x => x).ToList();
197208
tmp.Sort(comparer);
198209
tmp.Select((t, i) => arr[i] = tmp[i]);
199210
}

tests/JsonLD.Test/ConformanceTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5-
using System.Threading.Tasks;
65

76
using Newtonsoft.Json.Linq;
87
using Xunit;
@@ -22,11 +21,11 @@ public void ConformanceTestPasses(string id, string testname, ConformanceCase co
2221
JToken result = conformanceCase.run();
2322
if (id.Contains("error"))
2423
{
25-
Assert.True(((string)result["error"]).StartsWith((string)conformanceCase.error), "errors don't match");
24+
Assert.True(((string)result["error"]).StartsWith((string)conformanceCase.error), "Resulting error doesn't match expectations.");
2625
}
2726
else
2827
{
29-
Assert.True(JsonLdUtils.DeepCompare(result, conformanceCase.output), "returned JSON matches expectations");
28+
Assert.True(JsonLdUtils.DeepCompare(result, conformanceCase.output), "Returned JSON doesn't match expectations.");
3029
}
3130
}
3231
}

tests/JsonLD.Test/JsonLD.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<FileAlignment>512</FileAlignment>
1414
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1515
<RestorePackages>true</RestorePackages>
16+
<TargetFrameworkProfile>
17+
</TargetFrameworkProfile>
1618
</PropertyGroup>
1719
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1820
<DebugSymbols>true</DebugSymbols>
@@ -22,6 +24,7 @@
2224
<DefineConstants>DEBUG;TRACE</DefineConstants>
2325
<ErrorReport>prompt</ErrorReport>
2426
<WarningLevel>4</WarningLevel>
27+
<Prefer32Bit>false</Prefer32Bit>
2528
</PropertyGroup>
2629
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2730
<DebugType>pdbonly</DebugType>
@@ -30,6 +33,7 @@
3033
<DefineConstants>TRACE</DefineConstants>
3134
<ErrorReport>prompt</ErrorReport>
3235
<WarningLevel>4</WarningLevel>
36+
<Prefer32Bit>false</Prefer32Bit>
3337
</PropertyGroup>
3438
<ItemGroup>
3539
<Reference Include="Newtonsoft.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">

0 commit comments

Comments
 (0)