1

Closed

JContainer Contains function not working for jProperty?

description

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))
   jCont.Add(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.
Thanks,
Paulo
Closed Jul 23, 2013 at 12:45 PM by JamesNK
Ask on stackoverflow

comments

JamesNK wrote Jul 20, 2013 at 5:06 AM

Contains tests object reference equality

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

PauloPinto wrote Jul 20, 2013 at 5: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?