Exemplo n.º 1
0
        private static void MapAssemblyReferences(
            DependencyAnalyzerResult result,
            AppDomain appDomainWithBindingRedirects,
            VisualizerOptions options)
        {
            var copyOfAssemblies = new AssemblyReferenceInfo[result.Assemblies.Count];

            result.Assemblies.Values.CopyTo(copyOfAssemblies, 0);
            foreach (var assembly in copyOfAssemblies)
            {
                foreach (var referencedAssembly in assembly.ReflectionOnlyAssembly.GetReferencedAssemblies())
                {
                    var referencedAssemblyReferenceInfo = GetAssemblyReferenceInfo(
                        result.Assemblies,
                        referencedAssembly,
                        appDomainWithBindingRedirects,
                        options);

                    if (referencedAssemblyReferenceInfo != null)
                    {
                        assembly.AddReference(referencedAssemblyReferenceInfo);
                        referencedAssemblyReferenceInfo.AddReferencedBy(assembly);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private AssemblyReferenceInfo GetAssemblyReferenceInfo(IDictionary <string, AssemblyReferenceInfo> assemblies, AssemblyName assemblyName)
        {
            if (SkipSystem && AssemblyInformationProvider.IsSystemAssembly(assemblyName))
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(ReferencedStartsWith) && !assemblyName.FullName.StartsWith(ReferencedStartsWith, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var assemblyFullName = AppDomainWithBindingRedirects != null?AppDomainWithBindingRedirects.ApplyPolicy(assemblyName.FullName) : assemblyName.FullName;

            AssemblyReferenceInfo assemblyReferenceInfo;

            if (assemblies.TryGetValue(assemblyFullName, out assemblyReferenceInfo))
            {
                return(assemblyReferenceInfo);
            }

            assemblyReferenceInfo = new AssemblyReferenceInfo(assemblyName, new AssemblyName(assemblyFullName));
            assemblies.Add(assemblyFullName, assemblyReferenceInfo);
            return(assemblyReferenceInfo);
        }
Exemplo n.º 3
0
        private static AssemblyReferenceInfo GetAssemblyReferenceInfo(
            IDictionary <string, AssemblyReferenceInfo> assemblies,
            AssemblyName assemblyName,
            AppDomain appDomainWithBindingRedirects,
            VisualizerOptions options,
            string fileName = "")
        {
            if (options.SkipSystem && AssemblyInformationProvider.IsSystemAssembly(assemblyName))
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(options.ReferencedStartsWith) &&
                !assemblyName.FullName.StartsWith(options.ReferencedStartsWith, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var assemblyFullName = appDomainWithBindingRedirects != null
                ? appDomainWithBindingRedirects.ApplyPolicy(assemblyName.FullName)
                : assemblyName.FullName;

            if (assemblies.TryGetValue(assemblyFullName, out AssemblyReferenceInfo assemblyReferenceInfo))
            {
                return(assemblyReferenceInfo);
            }

            assemblyReferenceInfo = new AssemblyReferenceInfo(assemblyName, new AssemblyName(assemblyFullName), fileName);
            assemblies.Add(assemblyFullName, assemblyReferenceInfo);
            return(assemblyReferenceInfo);
        }
Exemplo n.º 4
0
        private static AssemblyReferenceInfo GetAssemblyReferenceInfo(IDictionary <string, AssemblyReferenceInfo> assemblies, AssemblyName assemblyName)
        {
            AssemblyReferenceInfo assemblyReferenceInfo;

            if (assemblies.TryGetValue(assemblyName.FullName, out assemblyReferenceInfo))
            {
                return(assemblyReferenceInfo);
            }

            assemblyReferenceInfo = new AssemblyReferenceInfo(assemblyName);
            assemblies.Add(assemblyName.FullName, assemblyReferenceInfo);
            return(assemblyReferenceInfo);
        }
Exemplo n.º 5
0
        private AssemblyReferenceInfo GetAssemblyReferenceInfo(IDictionary <string, AssemblyReferenceInfo> assemblies, AssemblyName assemblyName)
        {
            var assemblyFullName = AppDomainWithBindingRedirects != null?AppDomainWithBindingRedirects.ApplyPolicy(assemblyName.FullName) : assemblyName.FullName;

            AssemblyReferenceInfo assemblyReferenceInfo;

            if (assemblies.TryGetValue(assemblyFullName, out assemblyReferenceInfo))
            {
                return(assemblyReferenceInfo);
            }

            assemblyReferenceInfo = new AssemblyReferenceInfo(assemblyName, new AssemblyName(assemblyFullName));
            assemblies.Add(assemblyFullName, assemblyReferenceInfo);
            return(assemblyReferenceInfo);
        }
Exemplo n.º 6
0
 public void SetAlternativeFoundVersion(AssemblyReferenceInfo alternativeVersion)
 {
     if (alternativeVersion.AssemblyName.Name != AssemblyName.Name)
     {
         throw new InvalidOperationException(
                   $"Alternative version to {AssemblyName.Name}, must have the same Name, but is {alternativeVersion.AssemblyName.Name}");
     }
     if (ReflectionOnlyAssembly != null)
     {
         throw new InvalidOperationException(
                   $"AssemblyReferenceInfo for {AssemblyName.Name} has a ReflectionOnlyAssembly, so an alternative should not be set.");
     }
     if (AssemblySource != AssemblySource.NotFound)
     {
         throw new InvalidOperationException(
                   $"AssemblyReferenceInfo.AssemblySource for {AssemblyName.Name} is not 'NotFound', so an alternative should not be set.");
     }
     AlternativeFoundVersion = alternativeVersion;
 }
Exemplo n.º 7
0
 public void AddRoot(AssemblyReferenceInfo root) => roots.Add(root);
Exemplo n.º 8
0
 private static bool IsNotFound(AssemblyReferenceInfo assemblyInfo)
 {
     return(assemblyInfo.AssemblySource == AssemblySource.NotFound && !assemblyInfo.HasAlternativeVersion);
 }