Skip to content

Commit 4d16099

Browse files
committed
Support for Newtonsoft.Json 4.0.1 down to 4.0.1.
1 parent f817674 commit 4d16099

17 files changed

+76
-96
lines changed

src/JsonLD/Core/Context.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public virtual JsonLD.Core.Context Parse(JToken localContext, List<string> remot
289289
}
290290
// 3.7
291291
IDictionary<string, bool> defined = new Dictionary<string, bool>();
292-
foreach (string key in ((IDictionary<string, JToken>)eachContext).Keys)
292+
foreach (string key in eachContext.GetKeys())
293293
{
294294
if ("@base".Equals(key) || "@vocab".Equals(key) || "@language".Equals(key))
295295
{
@@ -466,8 +466,7 @@ private void CreateTermDefinition(JObject context, string term
466466
}
467467
if (termDefinitions.ContainsKey(prefix))
468468
{
469-
definition["@id"] = ((IDictionary<string, JToken>)termDefinitions[prefix])["@id"]
470-
+ suffix;
469+
definition["@id"] = (string)(((IDictionary<string, JToken>)termDefinitions[prefix])["@id"]) + suffix;
471470
}
472471
else
473472
{
@@ -479,7 +478,7 @@ private void CreateTermDefinition(JObject context, string term
479478
// 15)
480479
if (this.ContainsKey("@vocab"))
481480
{
482-
definition["@id"] = this["@vocab"] + term;
481+
definition["@id"] = (string)this["@vocab"] + term;
483482
}
484483
else
485484
{
@@ -586,7 +585,7 @@ internal virtual string ExpandIri(string value, bool relative, bool vocab, JObje
586585
// 5)
587586
if (vocab && this.ContainsKey("@vocab"))
588587
{
589-
return this["@vocab"] + value;
588+
return (string)this["@vocab"] + value;
590589
}
591590
else
592591
{
@@ -863,7 +862,7 @@ internal virtual string CompactIri(string iri, JToken value, bool relativeToVoca
863862
// 4)
864863
string compactIRI = null;
865864
// 5)
866-
foreach (string term_1 in ((IDictionary<string,JToken>)termDefinitions).Keys)
865+
foreach (string term_1 in termDefinitions.GetKeys())
867866
{
868867
JToken termDefinitionToken = termDefinitions[term_1];
869868
// 5.1)
@@ -954,7 +953,7 @@ public virtual JObject GetInverse()
954953
}
955954
// create term selections for each mapping in the context, ordererd by
956955
// shortest and then lexicographically least
957-
JArray terms = new JArray(((IDictionary<string,JToken>)termDefinitions).Keys);
956+
JArray terms = new JArray(termDefinitions.GetKeys());
958957
((JArray)terms).SortInPlace(new _IComparer_794());
959958
foreach (string term in terms)
960959
{
@@ -1212,14 +1211,14 @@ public virtual JToken ExpandValue(string activeProperty, JToken value)
12121211
{
12131212
// TODO: i'm pretty sure value should be a string if the @type is
12141213
// @id
1215-
rval["@id"] = ExpandIri(value.ToString(), true, false, null, null);
1214+
rval["@id"] = ExpandIri((string)value, true, false, null, null);
12161215
return rval;
12171216
}
12181217
// 2)
12191218
if (td != null && td["@type"].SafeCompare("@vocab"))
12201219
{
12211220
// TODO: same as above
1222-
rval["@id"] = ExpandIri(value.ToString(), true, true, null, null);
1221+
rval["@id"] = ExpandIri((string)value, true, true, null, null);
12231222
return rval;
12241223
}
12251224
// 3)
@@ -1278,7 +1277,7 @@ public virtual JObject Serialize()
12781277
{
12791278
ctx["@vocab"] = this["@vocab"];
12801279
}
1281-
foreach (string term in ((IDictionary<string,JToken>)termDefinitions).Keys)
1280+
foreach (string term in termDefinitions.GetKeys())
12821281
{
12831282
JObject definition = (JObject)termDefinitions[term];
12841283
if (definition["@language"].IsNull() && definition["@container"].IsNull() && definition

src/JsonLD/Core/JsonLdApi.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
120120
// 6)
121121
JObject result = new JObject();
122122
// 7)
123-
JArray keys = new JArray(elem.Keys);
123+
JArray keys = new JArray(element.GetKeys());
124124
keys.SortInPlace();
125125
foreach (string expandedProperty in keys)
126126
{
@@ -170,7 +170,7 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
170170
// 7.2.1)
171171
JObject compactedValue = (JObject)Compact(activeCtx, "@reverse", expandedValue, compactArrays);
172172
// 7.2.2)
173-
List<string> properties = new List<string>(((IDictionary<string, JToken>)compactedValue).Keys);
173+
List<string> properties = new List<string>(compactedValue.GetKeys());
174174
foreach (string property in properties)
175175
{
176176
JToken value = compactedValue[property];
@@ -489,7 +489,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
489489
// 6)
490490
JObject result = new JObject();
491491
// 7)
492-
JArray keys = new JArray(elem.Keys);
492+
JArray keys = new JArray(element.GetKeys());
493493
keys.SortInPlace();
494494
foreach (string key in keys)
495495
{
@@ -679,7 +679,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
679679
if (((IDictionary<string, JToken>)expandedValue).ContainsKey("@reverse"))
680680
{
681681
JObject reverse = (JObject)((JObject)expandedValue)["@reverse"];
682-
foreach (string property in ((IDictionary<string,JToken>)reverse).Keys)
682+
foreach (string property in reverse.GetKeys())
683683
{
684684
JToken item = reverse[property];
685685
// 7.4.11.2.1)
@@ -709,7 +709,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
709709
// 7.4.11.3.2)
710710
JObject reverseMap = (JObject)result["@reverse"];
711711
// 7.4.11.3.3)
712-
foreach (string property in ((IDictionary<string,JToken>)expandedValue).Keys)
712+
foreach (string property in expandedValue.GetKeys())
713713
{
714714
if ("@reverse".Equals(property))
715715
{
@@ -771,7 +771,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
771771
// 7.5.1)
772772
expandedValue = new JArray();
773773
// 7.5.2)
774-
foreach (string language in ((IDictionary<string, JToken>)value).Keys)
774+
foreach (string language in value.GetKeys())
775775
{
776776
JToken languageValue = ((IDictionary<string, JToken>)value)[language];
777777
// 7.5.2.1)
@@ -806,7 +806,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
806806
// 7.6.1)
807807
expandedValue = new JArray();
808808
// 7.6.2)
809-
JArray indexKeys = new JArray(((IDictionary<string,JToken>)value).Keys);
809+
JArray indexKeys = new JArray(value.GetKeys());
810810
indexKeys.SortInPlace();
811811
foreach (string index in indexKeys)
812812
{
@@ -926,7 +926,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
926926
// 8.1)
927927
// TODO: is this method faster than just using containsKey for
928928
// each?
929-
ICollection<string> keySet = new HashSet<string>(((IDictionary<string, JToken>)result).Keys);
929+
ICollection<string> keySet = new HashSet<string>(result.GetKeys());
930930
keySet.Remove("@value");
931931
keySet.Remove("@index");
932932
bool langremoved = keySet.Remove("@language");
@@ -1250,7 +1250,7 @@ internal virtual void GenerateNodeMap(JToken element, JObject
12501250
JObject reverseMap = (JObject)JsonLD.Collections.Remove
12511251
(elem, "@reverse");
12521252
// 6.9.3)
1253-
foreach (string property in ((IDictionary<string,JToken>)reverseMap).Keys)
1253+
foreach (string property in reverseMap.GetKeys())
12541254
{
12551255
JArray values = (JArray)reverseMap[property];
12561256
// 6.9.3.1)
@@ -1268,7 +1268,7 @@ internal virtual void GenerateNodeMap(JToken element, JObject
12681268
null, null);
12691269
}
12701270
// 6.11)
1271-
JArray keys = new JArray(elem.Keys);
1271+
JArray keys = new JArray(element.GetKeys());
12721272
keys.SortInPlace();
12731273
foreach (string property_1 in keys)
12741274
{
@@ -1414,7 +1414,7 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
14141414
bool embedOn = GetFrameFlag(frame, "@embed", state.embed);
14151415
bool explicicOn = GetFrameFlag(frame, "@explicit", state.@explicit);
14161416
// add matches to output
1417-
JArray ids = new JArray(((IDictionary<string,JToken>)matches).Keys);
1417+
JArray ids = new JArray(matches.GetKeys());
14181418
ids.SortInPlace();
14191419
foreach (string id in ids)
14201420
{
@@ -1477,7 +1477,7 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
14771477
state.embeds[id] = embeddedNode;
14781478
// iterate over subject properties
14791479
JObject element = (JObject)matches[id];
1480-
JArray props = new JArray(((IDictionary<string,JToken>)element).Keys);
1480+
JArray props = new JArray(element.GetKeys());
14811481
props.SortInPlace();
14821482
foreach (string prop in props)
14831483
{
@@ -1555,7 +1555,7 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
15551555
}
15561556
}
15571557
// handle defaults
1558-
props = new JArray(((IDictionary<string,JToken>)frame).Keys);
1558+
props = new JArray(frame.GetKeys());
15591559
props.SortInPlace();
15601560
foreach (string prop_1 in props)
15611561
{
@@ -1684,7 +1684,7 @@ private static void RemoveDependents(IDictionary<string, JsonLdApi.EmbedNode> em
16841684
private JObject FilterNodes(JsonLdApi.FramingContext state, JObject nodes, JObject frame)
16851685
{
16861686
JObject rval = new JObject();
1687-
foreach (string id in ((IDictionary<string,JToken>)nodes).Keys)
1687+
foreach (string id in nodes.GetKeys())
16881688
{
16891689
JObject element = (JObject)nodes[id];
16901690
if (element != null && FilterNode(state, element, frame))
@@ -1741,7 +1741,7 @@ private bool FilterNode(JsonLdApi.FramingContext state, JObject node, JObject fr
17411741
}
17421742
else
17431743
{
1744-
foreach (string key in ((IDictionary<string,JToken>)frame).Keys)
1744+
foreach (string key in frame.GetKeys())
17451745
{
17461746
if ("@id".Equals(key) || !JsonLdUtils.IsKeyword(key) && !(node.ContainsKey(key)))
17471747
{
@@ -1817,7 +1817,7 @@ private void EmbedValues(JsonLdApi.FramingContext state, JObject element, string
18171817
s = new JObject();
18181818
s["@id"] = sid;
18191819
}
1820-
foreach (string prop in ((IDictionary<string,JToken>)s).Keys)
1820+
foreach (string prop in s.GetKeys())
18211821
{
18221822
// copy keywords
18231823
if (JsonLdUtils.IsKeyword(prop))
@@ -2005,7 +2005,7 @@ public virtual JArray FromRDF(RDFDataset dataset)
20052005
}
20062006
}
20072007
// 4)
2008-
foreach (string name_1 in ((IDictionary<string,JToken>)graphMap).Keys)
2008+
foreach (string name_1 in graphMap.GetKeys())
20092009
{
20102010
JObject graph = (JObject)graphMap[name_1];
20112011
// 4.1)
@@ -2077,7 +2077,7 @@ public virtual JArray FromRDF(RDFDataset dataset)
20772077
// 5)
20782078
JArray result = new JArray();
20792079
// 6)
2080-
JArray ids = new JArray(((IDictionary<string,JToken>)defaultGraph).Keys);
2080+
JArray ids = new JArray(defaultGraph.GetKeys());
20812081
ids.SortInPlace();
20822082
foreach (string subject_1 in ids)
20832083
{
@@ -2088,7 +2088,7 @@ public virtual JArray FromRDF(RDFDataset dataset)
20882088
// 6.1.1)
20892089
node["@graph"] = new JArray();
20902090
// 6.1.2)
2091-
JArray keys = new JArray(((IDictionary<string,JToken>)graphMap[subject_1]).Keys);
2091+
JArray keys = new JArray(graphMap[subject_1].GetKeys());
20922092
keys.SortInPlace();
20932093
foreach (string s in keys)
20942094
{
@@ -2125,7 +2125,7 @@ public virtual RDFDataset ToRDF()
21252125
nodeMap["@default"] = new JObject();
21262126
GenerateNodeMap(this.value, nodeMap);
21272127
RDFDataset dataset = new RDFDataset(this);
2128-
foreach (string graphName in ((IDictionary<string,JToken>)nodeMap).Keys)
2128+
foreach (string graphName in nodeMap.GetKeys())
21292129
{
21302130
// 4.1)
21312131
if (JsonLdUtils.IsRelativeIri(graphName))
@@ -2151,7 +2151,7 @@ public virtual JToken Normalize(JObject dataset)
21512151
// create quads and map bnodes to their associated quads
21522152
JArray quads = new JArray();
21532153
JObject bnodes = new JObject();
2154-
foreach (string graphName in ((IDictionary<string,JToken>)dataset).Keys)
2154+
foreach (string graphName in dataset.GetKeys())
21552155
{
21562156
var eachGraphName = graphName;
21572157
JArray triples = (JArray)dataset[eachGraphName];
@@ -2198,7 +2198,7 @@ public virtual JToken Normalize(JObject dataset)
21982198
// mapping complete, start canonical naming
21992199
NormalizeUtils normalizeUtils = new NormalizeUtils(quads, bnodes, new UniqueNamer
22002200
("_:c14n"), opts);
2201-
return normalizeUtils.HashBlankNodes(((IDictionary<string,JToken>)bnodes).Keys);
2201+
return normalizeUtils.HashBlankNodes(bnodes.GetKeys());
22022202
}
22032203

22042204
private sealed class _Dictionary_1910 : JObject

src/JsonLD/Core/JsonLdProcessor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static JToken Flatten(JToken input, JToken context, JsonLdOptions opts)
158158
JObject defaultGraph = (JObject)JsonLD.Collections.Remove
159159
(nodeMap, "@default");
160160
// 4)
161-
foreach (string graphName in ((IDictionary<string,JToken>)nodeMap).Keys)
161+
foreach (string graphName in nodeMap.GetKeys())
162162
{
163163
JObject graph = (JObject)nodeMap[graphName];
164164
// 4.1+4.2)
@@ -180,7 +180,7 @@ public static JToken Flatten(JToken input, JToken context, JsonLdOptions opts)
180180
{
181181
entry["@graph"] = new JArray();
182182
}
183-
JArray keys = new JArray(((IDictionary<string,JToken>)graph).Keys);
183+
JArray keys = new JArray(graph.GetKeys());
184184
keys.SortInPlace();
185185
foreach (string id in keys)
186186
{
@@ -194,7 +194,7 @@ public static JToken Flatten(JToken input, JToken context, JsonLdOptions opts)
194194
// 5)
195195
JArray flattened = new JArray();
196196
// 6)
197-
JArray keys_1 = new JArray(((IDictionary<string,JToken>)defaultGraph).Keys);
197+
JArray keys_1 = new JArray(defaultGraph.GetKeys());
198198
keys_1.SortInPlace();
199199
foreach (string id_1 in keys_1)
200200
{

src/JsonLD/Core/JsonLdUtils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static bool DeepCompare(JToken v1, JToken v2, bool listOrderMatters)
7272
{
7373
return false;
7474
}
75-
foreach (string key in ((IDictionary<string,JToken>)m1).Keys)
75+
foreach (string key in m1.GetKeys())
7676
{
7777
if (!((IDictionary<string,JToken>)m2).ContainsKey(key) ||
7878
!DeepCompare(m1[key], m2[key], listOrderMatters))
@@ -414,7 +414,7 @@ internal static JArray ExpandLanguageMap(JObject languageMap
414414
)
415415
{
416416
JArray rval = new JArray();
417-
IList<string> keys = new List<string>(((IDictionary<string, JToken>)languageMap).Keys);
417+
IList<string> keys = new List<string>(languageMap.GetKeys());
418418
keys.SortInPlace();
419419
// lexicographically sort languages
420420
foreach (string key in keys)
@@ -625,7 +625,7 @@ internal static JToken RemovePreserve(Context ctx, JToken input, JsonLdOptions o
625625
return input;
626626
}
627627
// recurse through properties
628-
foreach (string prop in ((IDictionary<string,JToken>)input).Keys)
628+
foreach (string prop in input.GetKeys())
629629
{
630630
JToken result = RemovePreserve(ctx, ((JObject)input)[prop], opts
631631
);
@@ -899,7 +899,7 @@ private static void Resolve(JToken input, JObject cycles)
899899
}
900900
// queue all unresolved URLs
901901
JArray queue = new JArray();
902-
foreach (string url in ((IDictionary<string,JToken>)urls).Keys)
902+
foreach (string url in urls.GetKeys())
903903
{
904904
if (urls[url].SafeCompare(false))
905905
{
@@ -976,7 +976,7 @@ private static bool FindContextUrls(JToken input, JObject urls
976976
{
977977
if (input is JObject)
978978
{
979-
foreach (string key in ((IDictionary<string, JToken>)input).Keys)
979+
foreach (string key in input.GetKeys())
980980
{
981981
if (!"@context".Equals(key))
982982
{

src/JsonLD/Core/NormalizeUtils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public NormalizeUtils(JArray quads, JObject bnodes, UniqueNamer
2727

2828
// generates unique and duplicate hashes for bnodes
2929
/// <exception cref="JsonLD.Core.JsonLdError"></exception>
30-
public virtual JToken HashBlankNodes(ICollection<string> unnamed_)
30+
public virtual JToken HashBlankNodes(IEnumerable<string> unnamed_)
3131
{
3232
IList<string> unnamed = new List<string>(unnamed_);
3333
IList<string> nextUnnamed = new List<string>();
@@ -149,7 +149,7 @@ public virtual JToken HashBlankNodes(ICollection<string> unnamed_)
149149
// key-entry order
150150
// Note: key-order is preserved in
151151
// javascript
152-
foreach (string key in r.pathNamer.Existing().Keys)
152+
foreach (string key in r.pathNamer.Existing().GetKeys())
153153
{
154154
namer.GetName(key);
155155
}
@@ -253,7 +253,7 @@ private static NormalizeUtils.HashResult HashPaths(string id, JObject bnodes, Un
253253
if (hpi == quads.Count)
254254
{
255255
// done , hash groups
256-
groupHashes = new List<string>(((IDictionary<string,JToken>)groups).Keys);
256+
groupHashes = new List<string>(groups.GetKeys());
257257
groupHashes.SortInPlace();
258258
for (int hgi = 0; ; hgi++)
259259
{

0 commit comments

Comments
 (0)