2 // System.CodeDom.Compiler TempFileCollection Class implementation
5 // Dick Porter (dick@ximian.com)
7 // (C) Copyright 2003 Ximian, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
34 namespace System.CodeDom.Compiler
36 public class TempFileCollection:ICollection, IEnumerable, IDisposable
44 public TempFileCollection(): this(null, false)
48 public TempFileCollection(string tempDir): this(tempDir, false)
52 public TempFileCollection(string tempDir, bool keepFiles)
54 filehash=new Hashtable();
59 public string BasePath
64 /* Get the system temp dir */
65 MonoIO.GetTempPath(out tempdir);
71 string random = rnd.Next (10000,99999).ToString ();
72 basepath = Path.Combine (tempdir, random);
82 return(filehash.Count);
100 return(String.Empty);
107 public string AddExtension(string fileExtension)
109 return(AddExtension(fileExtension, keepfiles));
112 public string AddExtension(string fileExtension, bool keepFile)
114 string filename=BasePath+"."+fileExtension;
115 AddFile(filename, keepFile);
119 public void AddFile(string fileName, bool keepFile)
121 filehash.Add(fileName, keepFile);
124 public void CopyTo(string[] fileNames, int start)
126 filehash.Keys.CopyTo(fileNames, start);
129 void ICollection.CopyTo(Array array, int start)
131 filehash.Keys.CopyTo(array, start);
134 object ICollection.SyncRoot {
136 return filehash.SyncRoot;
140 bool ICollection.IsSynchronized {
146 void IDisposable.Dispose()
153 string[] filenames=new string[filehash.Count];
154 filehash.Keys.CopyTo(filenames, 0);
156 foreach(string file in filenames) {
157 if((bool)filehash[file]==false) {
159 filehash.Remove(file);
164 public IEnumerator GetEnumerator()
166 return(filehash.Keys.GetEnumerator());
169 protected virtual void Dispose(bool disposing)
174 ~TempFileCollection()