コード例 #1
0
        public static IEnumerable <string> GetReferencedAssembliesPath(this _Assembly assembly, string location, bool includeSystemAssemblies = false)
        {
            Log.Write("GetReferencedAssembliesPath Started - Parameters assembly: {0}, includeSystemAssemblies: {1}", assembly.ToString(), includeSystemAssemblies);
            List <string> retPaths = new List <string>();

            List <string> referencedAssemblies = assembly.GetReferencedAssemblies()
                                                 .Where(name => includeSystemAssemblies || !IsSystemAssembly(name.Name))
                                                 .Select(name => name.Name)
                                                 .ToList();

            if (!referencedAssemblies.Any())
            {
                return(retPaths);
            }
            Log.Write($"There are {referencedAssemblies.Count} referenced non system assemblies");

            Log.Write($"Current Assembly is at location {assembly.Location}");

            string currentAssemblyPath = string.Empty;

            try
            {
                currentAssemblyPath = FileSystem.Path.GetDirectoryName(location);
            }
            catch (Exception exception)
            {
                string context = $"GetDirectoryName of assembly: {assembly.FullName} failed. Path is wrong {location}";

                Log.Write(exception, context);
                RavenWrapper.Instance.Capture(exception, message: context);
            }


            if (string.IsNullOrEmpty(currentAssemblyPath))
            {
                return(Enumerable.Empty <string>());
            }

            Log.Write("currentAssemblyPath: {0}", currentAssemblyPath);

            referencedAssemblies
            .ForEach(s =>
            {
                Log.Write("Assembly {0} Located in {1} References Assembly {2} ", assembly.GetName().Name,
                          assembly.Location, s);
                retPaths.Add(FindPath(s, currentAssemblyPath));
            });

            return(retPaths.Where(s => !string.IsNullOrEmpty(s)));
        }
コード例 #2
0
        internal static bool ReferencesAssembly(this _Assembly assembly, Assembly referencedAssembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }
            if (referencedAssembly == null)
            {
                throw new ArgumentNullException(nameof(referencedAssembly));
            }

            string targetAssemblyName = referencedAssembly.GetName().Name;

            return(assembly.GetName().Name == targetAssemblyName || assembly.GetReferencedAssemblies().Any(r => r.Name == targetAssemblyName));
        }