static IEnumerator <string> LoadIterator() { using (FileStream stream = new FileStream(StateFile, FileMode.Open)) { ISurrogateSelector selector = new EnumerationSurrogateSelector(); IFormatter f = new SoapFormatter(selector, new StreamingContext()); return((IEnumerator <string>)f.Deserialize(stream)); } }
static void SaveIterator(IEnumerator <string> e) { using (FileStream stream = new FileStream(StateFile, FileMode.Create)) { ISurrogateSelector selector = new EnumerationSurrogateSelector(); IFormatter f = new SoapFormatter(selector, new StreamingContext()); f.Serialize(stream, e); } #region Note: The above code puts the name of the compiler-generated enumerator class... // into the serialized output. Under what circumstances, if any, might a recompile result in // a different class name? I have not yet investigated what the answer might be. // I suspect MS provide no guarantees in that regard. #endregion }