2 // System.CodeDom.Compiler TempFileCollection Class implementation
5 // Dick Porter (dick@ximian.com)
7 // (C) Copyright 2003 Ximian, Inc.
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
33 namespace System.CodeDom.Compiler
35 public class TempFileCollection:ICollection, IEnumerable, IDisposable
43 public TempFileCollection(): this(null, false)
47 public TempFileCollection(string tempDir): this(tempDir, false)
51 public TempFileCollection(string tempDir, bool keepFiles)
53 filehash=new Hashtable();
58 public string BasePath
63 /* Get the system temp dir */
64 MonoIO.GetTempPath(out tempdir);
70 string random = rnd.Next (10000,99999).ToString ();
71 basepath = Path.Combine (tempdir, random);
81 return(filehash.Count);
106 public string AddExtension(string fileExtension)
108 return(AddExtension(fileExtension, keepfiles));
111 public string AddExtension(string fileExtension, bool keepFile)
113 string filename=BasePath+"."+fileExtension;
114 AddFile(filename, keepFile);
118 public void AddFile(string fileName, bool keepFile)
120 filehash.Add(fileName, keepFile);
123 public void CopyTo(string[] fileNames, int start)
125 filehash.Keys.CopyTo(fileNames, start);
128 void ICollection.CopyTo(Array array, int start)
130 filehash.Keys.CopyTo(array, start);
133 object ICollection.SyncRoot {
135 return filehash.SyncRoot;
139 bool ICollection.IsSynchronized {
145 void IDisposable.Dispose()
152 string[] filenames=new string[filehash.Count];
153 filehash.Keys.CopyTo(filenames, 0);
155 foreach(string file in filenames) {
156 if((bool)filehash[file]==false) {
158 filehash.Remove(file);
163 public IEnumerator GetEnumerator()
165 return(filehash.Keys.GetEnumerator());
168 protected virtual void Dispose(bool disposing)
172 GC.SuppressFinalize (true);
176 ~TempFileCollection()