This project has moved and is read-only. For the latest updates, please go here.


JContainer Contains function not working for jProperty?


I'm trying to find if a JProperty is inside a JContainer, if not add it, so I have this code:
if (!jCont.Contains(jProp))
But I get an exception thrown by Add saying: "Can not add property id to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object."

The exception is right as jCont is a jContainer that does contain a jProperty with the exact same id as the jProp object (a jProperty object).

Is the Contains function returning the wrong result, or am I using the function wrong?

Any help appreciated.
Closed Jul 23, 2013 at 1:45 PM by JamesNK
Ask on stackoverflow


JamesNK wrote Jul 20, 2013 at 6:06 AM

Contains tests object reference equality

** Closed by JamesNK 7/19/2013 7:44 PM

wrote Jul 20, 2013 at 6:06 AM

PauloPinto wrote Jul 20, 2013 at 6:10 AM

My mistake. The question I asked was obviously not the one I really wanted to ask.

The question I really wanted to ask was:

How can I determine if a container already has a property with a specific id so that I can avoid running into the exception above?

wrote Jul 23, 2013 at 1:45 PM