2007-02-18 Marek Sieradzki <marek.sieradzki@gmail.com>
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / ImportCollection.cs
index 52d03c779835f91445ddad081fb049a3135be86b..988ac50e5641bc1961b11196f4ed07415691d1c0 100644 (file)
@@ -36,46 +36,55 @@ using System.Xml;
 namespace Microsoft.Build.BuildEngine {
        public class ImportCollection : ICollection, IEnumerable {
                
-               List <Import>   imports;
-               Project         parentProject;
+               GroupingCollection groupingCollection;
+               Dictionary <string, object> filenames;
                
-               internal ImportCollection (Project parentProject)
+               internal ImportCollection (GroupingCollection groupingCollection)
                {
-                       this.parentProject = parentProject;
-                       this.imports = new List <Import> ();
+                       this.groupingCollection = groupingCollection;
+                       filenames = new Dictionary <string, object> ();
                }
                
                internal void Add (Import import)
                {
-                       if (import == null)
-                               throw new ArgumentNullException ("import");
-                       
-                       if (imports.Contains (import))
-                               throw new InvalidOperationException ("Import already added.");
-                       
-                       imports.Add (import);
+                       if (!filenames.ContainsKey (import.ProjectPath)) {
+                               groupingCollection.Add (import);
+                               filenames.Add (import.ProjectPath, null);
+                       }
                }
                
-               [MonoTODO]
                public void CopyTo (Array array, int index)
                {
-                       throw new NotImplementedException ();
+                       if (array == null)
+                               throw new ArgumentNullException ("array");
+                       if (index < 0)
+                               throw new ArgumentOutOfRangeException ("Index was outside the bounds of the array.");
+                       if (array.Rank > 1)
+                               throw new ArgumentException ("array is multidimensional");
+                       if ((array.Length > 0) && (index >= array.Length))
+                               throw new ArgumentException ("Index was outside the bounds of the array.");
+                       if (index + this.Count > array.Length)
+                               throw new ArgumentException ("Not enough room from index to end of array for this BuildItemGroupCollection");
+
+                       IEnumerator it = GetEnumerator ();
+                       int i = index;
+                       while (it.MoveNext ()) {
+                               array.SetValue(it.Current, i++);
+                       }
                }
                
-               [MonoTODO]
                public void CopyTo (Import[] array, int index)
                {
-                       throw new NotImplementedException ();
+                       CopyTo ((Array) array, index);
                }
                
                public IEnumerator GetEnumerator ()
                {
-                       foreach (Import i in imports)
-                               yield return i;
+                       return groupingCollection.GetImportEnumerator ();
                }
                
                public int Count {
-                       get { return imports.Count; }
+                       get { return groupingCollection.Imports; }
                }
                
                public bool IsSynchronized  {
@@ -83,7 +92,7 @@ namespace Microsoft.Build.BuildEngine {
                }
                
                public object SyncRoot {
-                       get { return this; }
+                       get { return null; }
                }
        }
 }