Is there a way to serialize (using BinaryFormatter) the IEnumerator<T> that gets created when I use yield returns? The autogenerated class isn’t marked Serializable.
Is there a way to serialize (using BinaryFormatter ) the IEnumerator<T> that gets created
Share
The compiler generated enumerable does not have the [Serializable] attribute applied to it, so, no, out of the box you cannot do this.
You should ask yourself, “Why am I using a yield here, and what does it mean once this object is deserialized?”
If its convenience, you can use it to fill a type that can be serialized. If you use it to perform some heavy lifting in a lazy manner, you might want to consider changing your design to serialize/deserialize the information you need to perform that heavy lifting.