public IAssembly Resolve(IAssemblyReference value, string localPath)
        {
            foreach (IAssembly ia in _assemblyManager.Assemblies)
            {
                if (ia.CompareTo(value) == 0)
                {
                    return(ia);
                }
            }

            string   assemblyString = value.ToString();
            Assembly assembly       = null;

            try
            {
                assembly = AssemblyUtils.ResolveAssemblyFile(assemblyString, localPath);
                if (assembly == null)
                {
                    assembly = AssemblyUtils.LoadAssembly(assemblyString);
                }
            }
            catch
            {
            }

            if (assembly != null)
            {
                IAssembly ia = _assemblyManager.LoadFile(assembly.Location);
                return(ia);
            }

            return(null);
        }
        private IAssembly ResolveAssembly(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssemblyReference assemblyReference = this.ParseAssemblyReference(this.assembly, assemblyManager);

            for (int i = 0; i < assemblyManager.Assemblies.Count; i++)
            {
                IAssembly assembly = assemblyManager.Assemblies[i];
                if (assembly.Equals(assemblyReference))
                {
                    return(assembly);
                }
            }

            if (assemblyCache != null)
            {
                string location = assemblyCache.QueryLocation(assemblyReference, null);
                if ((location != null) && (location.Length > 0))
                {
                    IAssembly assembly = assemblyManager.LoadFile(location);
                    return(assembly);
                }
            }

            return(null);
        }
Exemple #3
0
    public static void Main()
    {
        IServiceProvider serviceProvider = new ApplicationManager(null);

        IAssemblyManager assemblyManager = (IAssemblyManager)serviceProvider.GetService(typeof(IAssemblyManager));

        IAssembly assembly = assemblyManager.LoadFile(typeof(CodeModelExample).Module.FullyQualifiedName);

        Console.WriteLine("Assembly: " + assembly.ToString());

        foreach (IModule module in assembly.Modules)
        {
            Console.WriteLine("Module: " + module.Name);

            foreach (ITypeDeclaration typeDeclaration in module.Types)
            {
                Console.WriteLine("Type: " + typeDeclaration.Namespace + "." + typeDeclaration.Name);

                foreach (IMethodDeclaration methodDeclaration in typeDeclaration.Methods)
                {
                    Console.WriteLine("Method: " + methodDeclaration);

                    IMethodBody methodBody = methodDeclaration.Body as IMethodBody;
                    if (methodBody != null)
                    {
                        foreach (IInstruction instruction in methodBody.Instructions)
                        {
                            Console.Write("L" + instruction.Offset.ToString("X4", CultureInfo.InvariantCulture));
                            Console.Write(": ");
                            Console.Write(InstructionTable.GetInstructionName(instruction.Code));

                            if (instruction.Value != null)
                            {
                                Console.Write(" ");

                                if (instruction.Value is string)
                                {
                                    Console.Write("\"");
                                }

                                Console.Write(instruction.Value.ToString());

                                if (instruction.Value is string)
                                {
                                    Console.Write("\"");
                                }
                            }


                            Console.WriteLine();
                        }
                    }
                }
            }
        }

        assemblyManager.Unload(assembly);
    }
Exemple #4
0
        private void LoadAssembies()
        {
            IServiceProvider serviceProvider  = new Reflector.ApplicationManager(new FakeReflectorWindowManager());
            IServiceProvider serviceProvider2 = new Reflector.ApplicationManager(new FakeReflectorWindowManager());
            IAssemblyManager assemblyManager  = (IAssemblyManager)serviceProvider.GetService(typeof(IAssemblyManager));
            IAssemblyManager assemblyManager2 = (IAssemblyManager)serviceProvider2.GetService(typeof(IAssemblyManager));

            Oassm = assemblyManager.LoadFile(OriginalAssembly.ItemSpec);
            Nassm = assemblyManager2.LoadFile(NewAssembly.ItemSpec);
            if (Oassm == Nassm)
            {
                throw new ArgumentException();
            }
        }
        private void ProcessCommandLineArguments()
        {
            CommandLineManager commandLineManger = new CommandLineManager();

            if (commandLineManger.IsArgumentPresent("assemblyListFile"))
            {
                string fileName = commandLineManger.GetArgument("assemblyListFile");
                if (false == File.Exists(fileName))
                {
                    MessageBox.Show(String.Format("Could not find file {0}", fileName));
                    return;
                }

                AssemblyListFile file             = new AssemblyListFile(fileName);
                string[]         assembliesToLoad = file.Assemblies;

                if (file.RemoveExisitingAssemblies)
                {
                    // Remove all exisiting assemblies
                    for (int i = assemblyManager.Assemblies.Count - 1; i >= 0; i--)
                    {
                        assemblyManager.Unload(assemblyManager.Assemblies[i]);
                    }
                }

                foreach (string assemblyFile in assembliesToLoad)
                {
                    assemblyManager.LoadFile(assemblyFile);
                }

                if (file.AutomaticallyResolveReferences)
                {
                    ResolveAllReferences(file.SupressResolveUI);
                }
            }

            if (commandLineManger.IsArgumentPresent("RegisterAssemblyListFileType"))
            {
                DoRegisterFileTypeAssociation();
            }

            if (commandLineManger.IsArgumentPresent("UnregisterAssemblyListFileType"))
            {
                DoUnregisterFileTypeAssociation();
            }
        }
 public AssemComp(string fileSpecA, string fileSpecB)
 {
     _errorCollector = (a, b) => { Reason += a + b + "\n"; };
     if (AssemComp.CheckFileSize(fileSpecA, fileSpecB))
     {
         IServiceProvider serviceProvider  = new Reflector.ApplicationManager(new FakeReflectorWindowManager());
         IServiceProvider serviceProvider2 = new Reflector.ApplicationManager(new FakeReflectorWindowManager());
         IAssemblyManager assemblyManager  = (IAssemblyManager)serviceProvider.GetService(typeof(IAssemblyManager));
         IAssemblyManager assemblyManager2 = (IAssemblyManager)serviceProvider2.GetService(typeof(IAssemblyManager));
         _assmA = assemblyManager.LoadFile(fileSpecA);
         _assmB = assemblyManager2.LoadFile(fileSpecB);
         if (_assmA == _assmB)
         {
             throw new ArgumentException();
         }
         AreEquivalent = Compare();
     }
     else
     {
         AreEquivalent = false;
         Reason        = "FileSize";
     }
 }
        private IAssembly ResolveAssembly(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssemblyReference assemblyReference = this.ParseAssemblyReference(this.assembly, assemblyManager);

            for (int i = 0; i < assemblyManager.Assemblies.Count; i++)
            {
                IAssembly assembly = assemblyManager.Assemblies[i];
                if (assembly.Equals(assemblyReference))
                {
                    return assembly;
                }
            }

            if (assemblyCache != null)
            {
                string location = assemblyCache.QueryLocation(assemblyReference, null);
                if ((location != null) && (location.Length > 0))
                {
                    IAssembly assembly = assemblyManager.LoadFile(location);
                    return assembly;
                }
            }

            return null;
        }