Author: jbevain
Date: 2007-05-31 12:32:19 -0400 (Thu, 31 May 2007)
New Revision: 78354

Modified:
   trunk/cecil/lib/ChangeLog
   trunk/cecil/lib/Mono.Cecil/BaseAssemblyResolver.cs
Log:
2007-05-31  Jb Evain  <[EMAIL PROTECTED]>

        * Mono.Cecil/BaseAssemblyResolver.cs:
                Improve resolve, works for people requiring
                .net 1.0 assemblies when they only have 1.1.


Modified: trunk/cecil/lib/ChangeLog
===================================================================
--- trunk/cecil/lib/ChangeLog   2007-05-31 16:26:52 UTC (rev 78353)
+++ trunk/cecil/lib/ChangeLog   2007-05-31 16:32:19 UTC (rev 78354)
@@ -1,3 +1,9 @@
+2007-05-31  Jb Evain  <[EMAIL PROTECTED]>
+
+       * Mono.Cecil/BaseAssemblyResolver.cs:
+               Improve resolve, works for people requiring
+               .net 1.0 assemblies when they only have 1.1.
+
 2007-05-30  Jb Evain  <[EMAIL PROTECTED]>
 
        * Mono.Cecil/DefaultAssemblyResolver.cs:

Modified: trunk/cecil/lib/Mono.Cecil/BaseAssemblyResolver.cs
===================================================================
--- trunk/cecil/lib/Mono.Cecil/BaseAssemblyResolver.cs  2007-05-31 16:26:52 UTC 
(rev 78353)
+++ trunk/cecil/lib/Mono.Cecil/BaseAssemblyResolver.cs  2007-05-31 16:32:19 UTC 
(rev 78354)
@@ -29,7 +29,6 @@
 namespace Mono.Cecil {
 
        using System;
-       using System.Collections;
        using System.IO;
        using SR = System.Reflection;
        using System.Text;
@@ -43,34 +42,53 @@
 
                public virtual AssemblyDefinition Resolve 
(AssemblyNameReference name)
                {
-                       string [] exts = new string [] { ".dll", ".exe" };
-                       IList dirs = new ArrayList ();
-                       dirs.Add (".");
-                       dirs.Add ("bin");
+                       AssemblyDefinition assembly;
+                       string frameworkdir = Path.GetDirectoryName (typeof 
(object).Module.FullyQualifiedName);
 
-                       if (IsZero (name.Version))
-                               dirs.Add (Path.GetDirectoryName (typeof 
(object).Module.FullyQualifiedName));
-
-                       foreach (string dir in dirs) {
-                               foreach (string ext in exts) {
-                                       string file = Path.Combine (dir, 
name.Name + ext);
-                                       if (File.Exists (file))
-                                               return 
AssemblyFactory.GetAssembly (file);
-                               }
+                       if (IsZero (name.Version)) {
+                               assembly = SearchDirectory (name, frameworkdir);
+                               if (assembly != null)
+                                       return assembly;
                        }
 
+                       assembly = SearchDirectory (name, ".", ".bin");
+                       if (assembly != null)
+                               return assembly;
+
 #if !CF_1_0 && !CF_2_0
-                       if (name.Name == "mscorlib")
-                               return GetCorlib (name);
+                       if (name.Name == "mscorlib") {
+                               assembly = GetCorlib (name);
+                               if (assembly != null)
+                                       return assembly;
+                       }
 
-                       AssemblyDefinition asm = GetAssemblyInGac (name);
-                       if (asm != null)
-                               return asm;
+                       assembly = GetAssemblyInGac (name);
+                       if (assembly != null)
+                               return assembly;
 #endif
 
+                       assembly = SearchDirectory (name, frameworkdir);
+                       if (assembly != null)
+                               return assembly;
+
                        throw new FileNotFoundException ("Could not resolve: " 
+ name);
                }
 
+               static readonly string [] _extentions = new string [] { ".dll", 
".exe" };
+
+               static AssemblyDefinition SearchDirectory 
(AssemblyNameReference name, params string [] directories)
+               {
+                       foreach (string dir in directories) {
+                               foreach (string ext in _extentions) {
+                                       string file = Path.Combine (dir, 
name.Name + ext);
+                                       if (File.Exists (file))
+                                               return 
AssemblyFactory.GetAssembly (file);
+                               }
+                       }
+
+                       return null;
+               }
+
 #if !CF_1_0 && !CF_2_0
                static AssemblyDefinition GetCorlib (AssemblyNameReference 
reference)
                {
@@ -101,7 +119,10 @@
                                        throw new NotSupportedException 
("Version not supported: " + reference.Version);
                        }
 
-                       return AssemblyFactory.GetAssembly (Path.Combine (path, 
"mscorlib.dll"));
+                       if (File.Exists (Path.Combine (path, "mscorlib.dll")))
+                               return AssemblyFactory.GetAssembly 
(Path.Combine (path, "mscorlib.dll"));
+
+                       return null;
                }
 
                static bool IsZero (Version version)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to