--- trunk/RomCheater/Serialization/SearchResultReader.cs 2012/06/21 06:30:33 402 +++ trunk/RomCheater/Serialization/SearchResultReader.cs 2012/06/21 07:13:04 403 @@ -12,6 +12,10 @@ namespace RomCheater.Serialization uint CurrentAddress(); void CurrentResult<TValue>(out TValue Value); TValue CurrentResult<TValue>(); + + bool ReadCurrentAddess { get; } + bool ReadCurrentValue { get; } + } public class SearchResultReader : SerializationReader, ISearchResultReader { @@ -44,7 +48,9 @@ namespace RomCheater.Serialization } catch (System.IO.EndOfStreamException) { } } - #region ISearchResultReader members + #region ISearchResultReader members + public bool ReadCurrentAddess { get; private set; } + public bool ReadCurrentValue { get; private set; } public uint CurrentAddress() { uint Address = 0; @@ -56,7 +62,13 @@ namespace RomCheater.Serialization Address = 0; try { + if (ReadCurrentAddess && !ReadCurrentValue) + { + throw new InvalidOperationException("Cannot read Current Address because the current Value has not been read. Please call CurrentResult<TValue>() first."); + } Address = binReader.ReadUInt32(); + ReadCurrentAddess = true; + ReadCurrentValue = false; } catch (System.IO.EndOfStreamException) { } } @@ -69,6 +81,10 @@ namespace RomCheater.Serialization public void CurrentResult<TValue>(out TValue Value) { Value = default(TValue); + if (!ReadCurrentAddess) + { + throw new InvalidOperationException("Cannot read Current Value because the current Address has not been read. Please call CurrentAddress() first."); + } try { Type t = typeof(TValue); @@ -99,6 +115,8 @@ namespace RomCheater.Serialization Value = (TValue)Convert.ChangeType(binReader.ReadInt64(), typeof(TValue)); break; } + ReadCurrentValue = true; + ReadCurrentAddess = false; } catch (System.IO.EndOfStreamException) { } } |