2 // System.CodeDom.Compiler TempFileCollection Class implementation
5 // Dick Porter (dick@ximian.com)
7 // (C) 2003 Ximian, Inc.
11 using System.Collections;
13 namespace System.CodeDom.Compiler
15 public class TempFileCollection:ICollection, IEnumerable, IDisposable
21 public TempFileCollection(): this(null, false)
25 public TempFileCollection(string tempDir): this(tempDir, false)
29 public TempFileCollection(string tempDir, bool keepFiles)
31 filehash=new Hashtable();
36 private string basepath=null;
38 public string BasePath
43 /* Get the system temp dir */
44 MonoIO.GetTempPath(out tempdir);
47 string random=new Random().Next(10000,99999).ToString();
49 basepath = Path.Combine (tempdir, random);
59 return(filehash.Count);
84 public string AddExtension(string fileExtension)
86 return(AddExtension(fileExtension, keepfiles));
89 public string AddExtension(string fileExtension, bool keepFile)
91 string filename=BasePath+"."+fileExtension;
92 AddFile(filename, keepFile);
96 public void AddFile(string fileName, bool keepFile)
98 filehash.Add(fileName, keepFile);
101 public void CopyTo(string[] fileNames, int start)
103 filehash.Keys.CopyTo(fileNames, start);
106 void ICollection.CopyTo(Array array, int start)
108 filehash.Keys.CopyTo(array, start);
111 object ICollection.SyncRoot {
113 return filehash.SyncRoot;
117 bool ICollection.IsSynchronized {
123 void IDisposable.Dispose()
130 string[] filenames=new string[filehash.Count];
131 filehash.Keys.CopyTo(filenames, 0);
133 foreach(string file in filenames) {
134 if((bool)filehash[file]==true) {
136 filehash.Remove(file);
141 public IEnumerator GetEnumerator()
143 return(filehash.Keys.GetEnumerator());
146 protected virtual void Dispose(bool disposing)
151 ~TempFileCollection()