/[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

revision 402 by william, Thu Jun 21 06:30:33 2012 UTC revision 403 by william, Thu Jun 21 07:13:04 2012 UTC
# Line 12  namespace RomCheater.Serialization Line 12  namespace RomCheater.Serialization
12          uint CurrentAddress();          uint CurrentAddress();
13          void CurrentResult<TValue>(out TValue Value);          void CurrentResult<TValue>(out TValue Value);
14          TValue CurrentResult<TValue>();          TValue CurrentResult<TValue>();
15    
16            bool ReadCurrentAddess { get; }
17            bool ReadCurrentValue { get; }
18    
19      }      }
20      public class SearchResultReader : SerializationReader, ISearchResultReader      public class SearchResultReader : SerializationReader, ISearchResultReader
21      {      {
# Line 44  namespace RomCheater.Serialization Line 48  namespace RomCheater.Serialization
48              }              }
49              catch (System.IO.EndOfStreamException) { }              catch (System.IO.EndOfStreamException) { }
50          }          }
51          #region ISearchResultReader members          #region ISearchResultReader members      
52            public bool ReadCurrentAddess { get; private set; }
53            public bool ReadCurrentValue { get; private set; }
54          public uint CurrentAddress()          public uint CurrentAddress()
55          {          {
56              uint Address = 0;              uint Address = 0;
# Line 56  namespace RomCheater.Serialization Line 62  namespace RomCheater.Serialization
62              Address = 0;              Address = 0;
63              try              try
64              {              {
65                    if (ReadCurrentAddess && !ReadCurrentValue)
66                    {
67                        throw new InvalidOperationException("Cannot read Current Address because the current Value has not been read. Please call CurrentResult<TValue>() first.");
68                    }
69                  Address = binReader.ReadUInt32();                  Address = binReader.ReadUInt32();
70                    ReadCurrentAddess = true;
71                    ReadCurrentValue = false;
72              }              }
73              catch (System.IO.EndOfStreamException) { }              catch (System.IO.EndOfStreamException) { }
74          }          }
# Line 69  namespace RomCheater.Serialization Line 81  namespace RomCheater.Serialization
81          public void CurrentResult<TValue>(out TValue Value)          public void CurrentResult<TValue>(out TValue Value)
82          {          {
83              Value = default(TValue);              Value = default(TValue);
84                if (!ReadCurrentAddess)
85                {
86                    throw new InvalidOperationException("Cannot read Current Value because the current Address has not been read. Please call CurrentAddress() first.");
87                }
88              try              try
89              {              {
90                  Type t = typeof(TValue);                  Type t = typeof(TValue);
# Line 99  namespace RomCheater.Serialization Line 115  namespace RomCheater.Serialization
115                          Value = (TValue)Convert.ChangeType(binReader.ReadInt64(), typeof(TValue));                          Value = (TValue)Convert.ChangeType(binReader.ReadInt64(), typeof(TValue));
116                          break;                          break;
117                  }                  }
118                    ReadCurrentValue = true;
119                    ReadCurrentAddess = false;
120              }              }
121              catch (System.IO.EndOfStreamException) { }              catch (System.IO.EndOfStreamException) { }
122          }          }

Legend:
Removed from v.402  
changed lines
  Added in v.403

  ViewVC Help
Powered by ViewVC 1.1.22