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

Comparing trunk/RomCheater/Serialization/SearchResultWriter.cs (file contents):
Revision 402 by william, Thu Jun 21 06:30:33 2012 UTC vs.
Revision 405 by william, Thu Jun 21 14:38:54 2012 UTC

--- trunk/RomCheater/Serialization/SearchResultWriter.cs	2012/06/21 06:30:33	402
+++ trunk/RomCheater/Serialization/SearchResultWriter.cs	2012/06/21 14:38:54	405
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.IO;
+using System.Diagnostics;
 
 namespace RomCheater.Serialization
 {
@@ -12,6 +13,9 @@ namespace RomCheater.Serialization
     }
     public class SearchResultWriter : SerializationWriter, ISearchResultWriter
     {
+
+        private int ResultsWritten = 0;
+
         public SearchResultWriter() : base() { }
         public SearchResultWriter(int resultCount) : base(resultCount) { WriteHeader(); }
         public SearchResultWriter(string filename) : base(filename) { WriteHeader(); }
@@ -51,6 +55,7 @@ namespace RomCheater.Serialization
                     binWriter.Write(Convert.ToInt64(value));
                     break;
             }
+            ResultsWritten++;
         }
         #endregion
 
@@ -63,5 +68,15 @@ namespace RomCheater.Serialization
             // write count (int)
             binWriter.Write(ResultCount);
         }
+
+        protected override void Dispose(bool disposing)
+        {
+            base.Dispose(disposing);
+            // ensure ResultCount and ResultsWritten are equal
+            if (ResultCount != ResultsWritten)
+            {
+                throw new InvalidOperationException(string.Format("ResultCount does not match ResultsWritten: 0x{0:x8} != 0x{1:x8}", ResultCount, ResultsWritten));
+            }            
+        }
     }
 }