Hello! I use the Newtonsoft.Json library to serialize objects. Faced with such a problem that I have an object that implements the IEnumerable<T> interface. And contains an array of objects as a property.

C #

 class TestObject { } [JsonObject] class TestObjects : IEnumerable<TestObject> { public int TestProperty { get; set; } readonly Collection<TestObject> objects; public TestObject[] Objects { get { return objects.ToArray(); } } public void Add(TestObject testObject) { objects.Add(testObject); } IEnumerator<TestObject> IEnumerable<TestObject>.GetEnumerator() { throw new System.NotImplementedException(); } IEnumerator IEnumerable.GetEnumerator() { throw new System.NotImplementedException(); } } var testObjects = new TestObjects { new TestObject() }; testObjects.TestProperty = 5; 

For my task, during deserialization, it is necessary to restore the Objects property, all objects, via the Add(TestObject) method.

How can this be implemented?

    0