-Fixed serializing certain objects with events

This commit is contained in:
James Newton-King
2016-01-05 16:26:22 +13:00
parent 865c08d95d
commit 1ada613903
2 changed files with 117 additions and 26 deletions
@@ -9199,6 +9199,41 @@ Path '', line 1, position 1.");
}
#endif
[Test]
public void SerializeObjectWithEvent()
{
MyObservableObject o = new MyObservableObject
{
TestString = "Test string"
};
string json = JsonConvert.SerializeObject(o, Formatting.Indented);
StringAssert.AreEqual(@"{
""PropertyChanged"": null,
""TestString"": ""Test string""
}", json);
MyObservableObject o2 = JsonConvert.DeserializeObject<MyObservableObject>(json);
Assert.AreEqual("Test string", o2.TestString);
}
public class MyObservableObject : ObservableObject
{
public new string PropertyChanged;
public string TestString { get; set; }
}
public class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected PropertyChangedEventHandler PropertyChangedHandler
{
get { return PropertyChanged; }
}
}
[Test]
public void ParameterizedConstructorWithBasePrivateProperties()
{