Resolve() public method

public Resolve ( Mono.Cecil.AssemblyNameReference name ) : AssemblyDefinition
name Mono.Cecil.AssemblyNameReference
return Mono.Cecil.AssemblyDefinition
Ejemplo n.º 1
0
        TypeDefinition FindTypeDefinition(Hashtable visited, AssemblyResolver resolver, string basePath, AssemblyDefinition asm, string fullName)
        {
            if (visited.Contains(asm))
            {
                return(null);
            }

            visited [asm] = asm;

            TypeDefinition cls = asm.MainModule.GetType(fullName);

            if (cls != null)
            {
                return(cls);
            }

            foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences)
            {
                AssemblyDefinition basm = resolver.Resolve(aref, basePath);
                if (basm != null)
                {
                    cls = basm.MainModule.GetType(fullName);
                    if (cls != null)
                    {
                        return(cls);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public CecilWidgetLibrary(AssemblyResolver resolver, string path)
        {
            name          = path;
            this.resolver = resolver;

            if (System.IO.File.Exists(path))
            {
                filename = path;
            }
            else if (resolver != null)
            {
                filename = resolver.Resolve(path, null);
            }

            if (filename == null)
            {
                filename = path;
            }
            else
            {
                filename = System.IO.Path.GetFullPath(filename);
            }

            RefreshFromCache();
        }
Ejemplo n.º 3
0
        void ScanLibraries(ArrayList list, Assembly asm)
        {
            foreach (AssemblyName aname in asm.GetReferencedAssemblies())
            {
                Assembly depasm = null;
                try {
                    depasm = Assembly.Load(aname);
                } catch {
                }

                if (depasm == null)
                {
                    string file = resolver != null?resolver.Resolve(aname.FullName, Path.GetDirectoryName(asm.Location)) : null;

                    if (file != null)
                    {
                        depasm = Assembly.LoadFrom(file);
                    }
                    else
                    {
                        throw new InvalidOperationException("Assembly not found: " + aname.FullName);
                    }
                }

                ManifestResourceInfo res = depasm.GetManifestResourceInfo("objects.xml");
                if (res != null)
                {
                    list.Add(depasm.Location);
                }
            }
        }
Ejemplo n.º 4
0
        public AssemblyWidgetLibrary(AssemblyResolver resolver, string assemblyPath)
        {
            this.name = assemblyPath;

            string ares = resolver.Resolve(assemblyPath, null);

            if (ares != null)
            {
                assemblyPath = ares;
            }

            this.resolver = resolver;
            if (assemblyPath.EndsWith(".dll") || assemblyPath.EndsWith(".exe"))
            {
                if (File.Exists(assemblyPath))
                {
                    assembly = Assembly.LoadFrom(assemblyPath);
                }
            }
            else
            {
                assembly = Assembly.Load(assemblyPath);
            }

            if (assembly == null)
            {
                throw new InvalidOperationException("Couldn't load assembly at " + assemblyPath);
            }

            UpdateCache();
        }
Ejemplo n.º 5
0
        bool ReferenceChainContainsGtk(AssemblyResolver resolver, AssemblyNameReference aref, Hashtable visited)
        {
            if (aref.Name == "gtk-sharp")
            {
                return(true);
            }
            else if (visited.Contains(aref.Name))
            {
                return(false);
            }

            visited [aref.Name] = aref;

            AssemblyDefinition adef = resolver.Resolve(aref);

            if (adef == null)
            {
                return(false);
            }

            foreach (AssemblyNameReference child in adef.MainModule.AssemblyReferences)
            {
                if (ReferenceChainContainsGtk(resolver, child, visited))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        AssemblyDefinition ResolveAssembly(AssemblyNameReference aref)
        {
            string bpath    = Path.Combine(Path.GetDirectoryName(filename), aref.Name);
            string filePath = null;

            if (resolver != null)
            {
                filePath = resolver.Resolve(aref.FullName, null);
            }

            if (filePath != null)
            {
                if (File.Exists(bpath + ".dll"))
                {
                    filePath = bpath + ".dll";
                }
                if (File.Exists(bpath + ".exe"))
                {
                    filePath = bpath + ".exe";
                }
            }

            AssemblyDefinition adef = null;

            if (filePath != null)
            {
                adef = AssemblyFactory.GetAssembly(filePath);
            }
            else
            {
                try {
                    adef = resolver.Resolve(aref);
                } catch {
                    // If can't resolve, just return null
                    return(null);
                }
            }

            return(adef);
        }
Ejemplo n.º 7
0
 void LoadLibraries(AssemblyResolver resolver, Hashtable visited, IEnumerable libraries)
 {
     // Convert all assembly names to assembly paths before registering the libraries.
     // The registry and the library cache will only handle full paths.
     foreach (string s in libraries)
     {
         string sr = resolver.Resolve(s, null);
         if (sr != null)
         {
             AddLibrary(resolver, visited, sr);
         }
     }
     Registry.ReloadWidgetLibraries();
 }
Ejemplo n.º 8
0
        public CecilWidgetLibrary(AssemblyResolver resolver, string path)
        {
            name = path;
            this.resolver = resolver;

            cache.Refresh (resolver, name);

            if (resolver != null)
                filename = resolver.Resolve (path, null);

            if (filename == null)
                filename = path;

            assembly = AssemblyFactory.GetAssembly (filename);
        }
		public CecilWidgetLibrary (AssemblyResolver resolver, string path)
		{
			name = path;
			this.resolver = resolver;

			if (System.IO.File.Exists (path))
				filename = path;
			else if (resolver != null)
				filename = resolver.Resolve (path, null);
			
			if (filename == null)
				filename = path;
			else
				filename = System.IO.Path.GetFullPath (filename);

			RefreshFromCache ();
		}
Ejemplo n.º 10
0
        void AddDependencies(XmlElement elem, AssemblyResolver resolver, string filename, AssemblyDefinition asm)
        {
            string dir = Path.GetDirectoryName(filename);

            foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences)
            {
                string file = null;
                if (resolver != null)
                {
                    resolver.Resolve(aref.FullName, dir);
                }
                if (file != null && Application.InternalIsWidgetLibrary(resolver, file))
                {
                    XmlElement edep = elem.OwnerDocument.CreateElement("dependency");
                    edep.InnerText = file;
                    elem.AppendChild(edep);
                }
            }
        }
Ejemplo n.º 11
0
        public CecilWidgetLibrary(AssemblyResolver resolver, string path)
        {
            name          = path;
            this.resolver = resolver;

            cache.Refresh(resolver, name);

            if (resolver != null)
            {
                filename = resolver.Resolve(path, null);
            }

            if (filename == null)
            {
                filename = path;
            }

            assembly = AssemblyFactory.GetAssembly(filename);
        }
		public AssemblyWidgetLibrary (AssemblyResolver resolver, string assemblyPath)
		{
			this.name = assemblyPath;
			
			string ares = resolver.Resolve (assemblyPath, null);
			if (ares != null)
				assemblyPath = ares;
			
			this.resolver = resolver;
			if (assemblyPath.EndsWith (".dll") || assemblyPath.EndsWith (".exe")) {
				if (File.Exists (assemblyPath))
					assembly = Assembly.LoadFrom (assemblyPath);
			} else
				assembly = Assembly.Load (assemblyPath);
				
			if (assembly == null)
				throw new InvalidOperationException ("Couldn't load assembly at " + assemblyPath);

			UpdateCache ();
		}
Ejemplo n.º 13
0
        internal static bool InternalIsWidgetLibrary(AssemblyResolver resolver, string assemblyRef)
        {
            string path;

            if (assemblyRef.EndsWith(".dll") || assemblyRef.EndsWith(".exe"))
            {
                if (!File.Exists(assemblyRef))
                {
                    return(false);
                }
                path = assemblyRef;
            }
            else
            {
                path = resolver.Resolve(assemblyRef, null);
                if (path == null)
                {
                    return(false);
                }
            }

            return(CecilWidgetLibrary.IsWidgetLibrary(path));
        }
Ejemplo n.º 14
0
        ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, TypeDefinition tdef)
        {
            if (tdef == null)
            {
                return(null);
            }

            ToolboxItemInfo info     = null;
            string          category = "General";

            foreach (CustomAttribute attr in tdef.CustomAttributes)
            {
                switch (attr.Constructor.DeclaringType.FullName)
                {
                case "System.ComponentModel.ToolboxItemAttribute":
                    attr.Resolve();
                    if (attr.ConstructorParameters.Count > 0)
                    {
                        object param = attr.ConstructorParameters [0];
                        if (param == null)
                        {
                            return(null);
                        }
                        else if (param.GetType() == typeof(bool))
                        {
                            if ((bool)param)
                            {
                                info = new ToolboxItemInfo("Gtk.Widget");
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else if (param.GetType() == typeof(System.Type))
                        {
                            info = new ToolboxItemInfo("Gtk.Widget");
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    break;

                case "System.ComponentModel.CategoryAttribute":
                    attr.Resolve();
                    if (attr.ConstructorParameters.Count > 0)
                    {
                        object param = attr.ConstructorParameters [0];
                        if (param.GetType() == typeof(string))
                        {
                            category = (string)param;
                        }
                    }
                    break;

                default:
                    continue;
                }
            }

            if (info == null && tdef.BaseType != null)
            {
                info = GetToolboxItemInfo(resolver, resolver.Resolve(tdef.BaseType));
            }

            if (info != null)
            {
                info.PaletteCategory = category;
            }

            return(info);
        }
Ejemplo n.º 15
0
 void AddDependencies(XmlElement elem, AssemblyResolver resolver, string filename, AssemblyDefinition asm)
 {
     string dir = Path.GetDirectoryName (filename);
     foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences) {
         string file = null;
         if (resolver != null)
             resolver.Resolve (aref.FullName, dir);
         if (file != null && Application.InternalIsWidgetLibrary (resolver, file)) {
             XmlElement edep = elem.OwnerDocument.CreateElement ("dependency");
             edep.InnerText = file;
             elem.AppendChild (edep);
         }
     }
 }
Ejemplo n.º 16
0
 AssemblyDefinition ResolveAssembly(AssemblyNameReference aref)
 {
     return(resolver.Resolve(aref, Path.GetDirectoryName(filename)));
 }
Ejemplo n.º 17
0
        ToolboxItemInfo GetToolboxItemInfo(AssemblyResolver resolver, TypeDefinition tdef)
        {
            if (tdef == null)
                return null;

            ToolboxItemInfo info = null;
            string category = "General";

            foreach (CustomAttribute attr in tdef.CustomAttributes) {
                switch (attr.Constructor.DeclaringType.FullName) {
                case "System.ComponentModel.ToolboxItemAttribute":
                    attr.Resolve ();
                    if (attr.ConstructorParameters.Count > 0) {
                        object param = attr.ConstructorParameters [0];
                        if (param == null)
                            return null;
                        else if (param.GetType () == typeof (bool)) {
                            if ((bool) param)
                                info = new ToolboxItemInfo ("Gtk.Widget");
                            else
                                return null;
                        } else if (param.GetType () == typeof (System.Type))
                            info = new ToolboxItemInfo ("Gtk.Widget");
                        else
                            return null;
                    }
                    break;
                case "System.ComponentModel.CategoryAttribute":
                    attr.Resolve ();
                    if (attr.ConstructorParameters.Count > 0) {
                        object param = attr.ConstructorParameters [0];
                        if (param.GetType () == typeof (string))
                            category = (string) param;
                    }
                    break;
                default:
                    continue;
                }

            }

            if (info == null && tdef.BaseType != null)
                info = GetToolboxItemInfo (resolver, resolver.Resolve (tdef.BaseType));

            if (info != null)
                info.PaletteCategory = category;

            return info;
        }
Ejemplo n.º 18
0
		bool ReferenceChainContainsGtk (AssemblyResolver resolver, AssemblyNameReference aref, Hashtable visited)
		{
			if (aref.Name == "gtk-sharp")
				return true;
			else if (visited.Contains (aref.Name))
				return false;

			visited [aref.Name] = aref;

			AssemblyDefinition adef = resolver.Resolve (aref);
			if (adef == null)
				return false;

			foreach (AssemblyNameReference child in adef.MainModule.AssemblyReferences)
				if (ReferenceChainContainsGtk (resolver, child, visited))
					return true;

			return false;
		}
Ejemplo n.º 19
0
		internal static bool InternalIsWidgetLibrary (AssemblyResolver resolver, string assemblyRef)
		{
			string path;

			if (assemblyRef.EndsWith (".dll") || assemblyRef.EndsWith (".exe")) {
				if (!File.Exists (assemblyRef))
					return false;
				path = assemblyRef;
			}
			else {
				path = resolver.Resolve (assemblyRef, null);
				if (path == null)
					return false;
			}

			return CecilWidgetLibrary.IsWidgetLibrary (path);
		}
Ejemplo n.º 20
0
		void LoadLibraries (AssemblyResolver resolver, Hashtable visited, IEnumerable libraries)
		{
			// Convert all assembly names to assembly paths before registering the libraries.
			// The registry and the library cache will only handle full paths.
			foreach (string s in libraries) {
				string sr = resolver.Resolve (s, null);
				if (sr != null)
					AddLibrary (resolver, visited, sr);
			}
			Registry.ReloadWidgetLibraries ();
		}
Ejemplo n.º 21
0
		TypeDefinition FindTypeDefinition (Hashtable visited, AssemblyResolver resolver, string basePath, AssemblyDefinition asm, string fullName)
		{
			if (visited.Contains (asm))
				return null;
				
			visited [asm] = asm;
			
			TypeDefinition cls = asm.MainModule.GetType (fullName);
			if (cls != null)
				return cls;
			
			foreach (AssemblyNameReference aref in asm.MainModule.AssemblyReferences) {
				AssemblyDefinition basm = resolver.Resolve (aref, basePath);
				if (basm != null) {
					cls = basm.MainModule.GetType (fullName);
					if (cls != null)
						return cls;
				}
			}
			return null;
		}