ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Serialization/SearchResultReader.cs
(Generate patch)

Comparing trunk/RomCheater/Serialization/SearchResultReader.cs (file contents):
Revision 402 by william, Thu Jun 21 06:30:33 2012 UTC vs.
Revision 403 by william, Thu Jun 21 07:13:04 2012 UTC

--- 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) { }
         }