JamesNK/Newtonsoft.Json — pull request #423 by D3-LucaPiombino (2014-11-11 12:50:48+00:00)
Title: Circular reference detection reference equality handling

I' ve closed the previous pull request and opened a new one.
I still think that the current behavior(see https://github.com/JamesNK/Newtonsoft.Json/issues/401) **IS** very fragile.
I undestand that if people are depending on it, the default
behavior cannot be changed, but maybe it should be at least overridable.
In this pull request i've added a new enum(ReferenceComparisonHandling) and a new property that allow to override the behavior, available to all the various levels available for other settings like **ReferenceLoopHandling**, **ItemReferenceLoopHandling** etc... that specify the method that will be used to compare references during the circular reference detection phase.
If the settings is not provided the old behavior is used.

```csharp
new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ReferenceComparisonHandling = ReferenceComparisonHandling.ReferenceEquals
}

[JsonObject(ItemReferenceComparisonHandling = ReferenceComparisonHandling.ReferenceEquals)]
[JsonProperty(ReferenceComparisonHandling = ReferenceComparisonHandling.ReferenceEquals)]
[JsonProperty(ItemReferenceComparisonHandling = ReferenceComparisonHandling.ReferenceEquals)]

```

and of course all the other classes that partecipate in the serialization pipeline(**JsonProperty**,**JsonContract**, etc...).
I've added a new set of unit test that verify the intended behavior as the guidelines indicates.
This could have also been implemented in a different way, by creating a new service (like IReferenceResolver) that allow to change the default behavior, but i didn't want to change the code to much. If you prefer this solution let me know , i can make another pull request.

Thanks.