Ejemplo n.º 1
0
        IEnumerable <AssemblyDef> GetResolvedContractAssemblies(ModuleDef module)
        {
            var nonContractAsms = new HashSet <IAssembly>(AssemblyNameComparer.CompareAll);
            var stack           = new Stack <AssemblyRef>(module.GetAssemblyRefs());

            while (stack.Count > 0)
            {
                cancellationToken.ThrowIfCancellationRequested();
                var asmRef = stack.Pop();
                if (!contractsPublicKeyToken.Equals(asmRef.PublicKeyOrToken?.Token))
                {
                    continue;
                }
                if (checkedContractsAssemblies.Contains(asmRef))
                {
                    continue;
                }
                checkedContractsAssemblies.Add(asmRef);

                var contractsAsm = module.Context.AssemblyResolver.Resolve(asmRef, module);
                if (contractsAsm != null)
                {
                    yield return(contractsAsm);

                    foreach (var m in contractsAsm.Modules)
                    {
                        foreach (var ar in m.GetAssemblyRefs())
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                            if (contractsPublicKeyToken.Equals(ar.PublicKeyOrToken))
                            {
                                stack.Push(ar);
                            }
                            else
                            {
                                nonContractAsms.Add(ar);
                            }
                        }
                    }
                }
            }
            foreach (var asmRef in nonContractAsms)
            {
                cancellationToken.ThrowIfCancellationRequested();
                var asm = module.Context.AssemblyResolver.Resolve(asmRef, module);
                if (asm != null)
                {
                    yield return(asm);
                }
            }
        }
Ejemplo n.º 2
0
 static bool IsPublicKeyToken(PublicKeyToken[] tokens, PublicKeyToken token)
 {
     foreach (var t in tokens)
     {
         if (token.Equals(t))
         {
             return(true);
         }
     }
     return(false);
 }