/[RomCheater]/trunk/RomCheater/Serialization/SearchResultReader.cs
ViewVC logotype

Diff of /trunk/RomCheater/Serialization/SearchResultReader.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- 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 @@
         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 @@
             }
             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 @@
             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 @@
         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 @@
                         Value = (TValue)Convert.ChangeType(binReader.ReadInt64(), typeof(TValue));
                         break;
                 }
+                ReadCurrentValue = true;
+                ReadCurrentAddess = false;
             }
             catch (System.IO.EndOfStreamException) { }
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22