public void EqualityComparer() { AccountWithEquals account = new AccountWithEquals { Name = "main" }; AccountWithEquals manager = new AccountWithEquals { Name = "main" }; account.Manager = manager; ExceptionAssert.Throws <JsonSerializationException>( () => JsonConvertX.SerializeObject(account), "Self referencing loop detected for property 'Manager' with type 'JsonExtensions.Tests.Serialization.AccountWithEquals'. Path ''."); string json = JsonConvertX.SerializeObject(account, new JsonSerializerSettings { EqualityComparer = new ReferenceEqualsEqualityComparer(), Formatting = Formatting.Indented }); StringAssert.AreEqual(@"{ ""Name"": ""main"", ""Manager"": { ""Name"": ""main"", ""Manager"": null } }", json); }
public override bool Equals(object obj) { AccountWithEquals a = obj as AccountWithEquals; if (a == null) { return(false); } return(Name == a.Name); }