noblethrasher

For comment 3424557

Jan 4th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. class FileEx
  2.     {
  3.         string path;
  4.         Func<string> current;
  5.         Func<bool> hasNext;
  6.        
  7.         public FileEx(string path, Func<string> current, Func<bool> hasNext)
  8.         {
  9.             this.path = path;
  10.             this.current = current;
  11.             this.hasNext = hasNext;
  12.         }
  13.  
  14.         public void WriteAll()
  15.         {
  16.             System.IO.StreamWriter sw = new System.IO.StreamWriter(path);
  17.  
  18.             try
  19.             {
  20.                 var line = current ();
  21.                
  22.                 while (hasNext ())
  23.                 {
  24.                     sw.WriteLine (line);
  25.                     line = current ();
  26.                 }
  27.             }
  28.             catch (Exception ex)
  29.             {
  30.                 throw;
  31.             }
  32.             finally
  33.             {
  34.                 sw.Close ();
  35.             }
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment