Newtonsoft.json: LINQ JObject not exporting ContainsKey

Created on 23 Mar 2016  路  4Comments  路  Source: JamesNK/Newtonsoft.Json

Hi

At
https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/Linq/JObject.cs#L544
ContainsKey is not public.
Where I could do

  float x = hash.ContainsKey('x') ? (float)hash['x'] : 0f;

I am needing to write

    float x;
   JToken t;
   if (hash.TryGetValue('x', out t)) {
      x= (float)t;
  } else { x = 0f; }

Or am I missing something?

Thanks

next-major

Most helpful comment

@ambs you could cast the JObject to a IDictionary<string, JToken> to get access to ContainsKey (though I agree you shouldn't have to)

All 4 comments

@ambs you could cast the JObject to a IDictionary<string, JToken> to get access to ContainsKey (though I agree you shouldn't have to)

Yep, can't recall how, but I solved the issue. But always good to have it explicitly.

I meant to make it public in 10 but I forgot. It will be public in 11.

Was this page helpful?
0 / 5 - 0 ratings