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

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

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

--- 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.Linq;
 using System.Text;
 using System.IO;
+using System.Diagnostics;
 
 namespace RomCheater.Serialization
 {
@@ -12,6 +13,9 @@
     }
     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 @@
                     binWriter.Write(Convert.ToInt64(value));
                     break;
             }
+            ResultsWritten++;
         }
         #endregion
 
@@ -63,5 +68,15 @@
             // 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));
+            }            
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22