Merge pull request #3585 from lateralusX/jlorenss/win-counter-warning
[mono.git] / mcs / class / System.Configuration / System.Configuration / ConfigurationLocationCollection.cs
index ded6567dd8d8c2b017e0317c83d6c638c8bde725..c59fad535e48b7e18d5920275837de116dfb7345 100644 (file)
@@ -26,8 +26,6 @@
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 
-#if NET_2_0
-
 using System.Collections;
 
 namespace System.Configuration {
@@ -39,7 +37,7 @@ namespace System.Configuration {
                }
                
                public ConfigurationLocation this [int index] {
-                       get { return this [index] as ConfigurationLocation; }
+                       get { return InnerList [index] as ConfigurationLocation; }
                }
                
                internal void Add (ConfigurationLocation loc)
@@ -50,11 +48,46 @@ namespace System.Configuration {
                internal ConfigurationLocation Find (string location)
                {
                        foreach (ConfigurationLocation loc in InnerList)
-                               if (loc.Path == location)
+                               if (String.Compare (loc.Path, location, StringComparison.OrdinalIgnoreCase) == 0)
                                        return loc;
                        return null;
                }
+
+               internal ConfigurationLocation FindBest (string location)
+               {
+                       if(String.IsNullOrEmpty (location))
+                               return null;
+                       
+                       ConfigurationLocation bestMatch = null;
+                       int locationlen = location.Length;
+                       int bestmatchlen = 0;
+                       
+                       foreach (ConfigurationLocation loc in InnerList) {
+                               string lpath = loc.Path;
+                               if (String.IsNullOrEmpty (lpath))
+                                       continue;
+                               
+                               int lpathlen = lpath.Length;
+                               if (location.StartsWith (lpath, StringComparison.OrdinalIgnoreCase)) {
+                                       // Exact match always takes precedence
+                                       if (locationlen == lpathlen)
+                                               return loc;
+                                       
+                                       // ensure path based comparisons consider full directory names (i.e. so 'admin' does not match an 'administration' path)
+                                       if(locationlen > lpathlen && location [lpathlen] != '/')
+                                               continue;
+
+                                       if(bestMatch == null)
+                                               bestMatch = loc;
+                                       else if (bestmatchlen < lpathlen) {
+                                               bestMatch = loc;
+                                               bestmatchlen = lpathlen;
+                                       }
+                               }
+                       }
+
+                       return bestMatch;
+               }
        }
 }
 
-#endif