private IEnumerable <Type> GetTypesFromBaseType(_Assembly assembly, Type baseType)
        {
            ReadOnlyCollection <Type> allTypesInAssembly;

            try
            {
                allTypesInAssembly = AssemblyTypeCache.GetTypes(assembly);
            }
            catch (ReflectionTypeLoadException ex)
            {
                string message = string.Format(
                    "The types from assembly '{0}' could not be loaded.{1}{2}",
                    assembly.GetName(),
                    Environment.NewLine,
                    string.Join(Environment.NewLine, ex.LoaderExceptions.Select(e => e.Message)));
                throw new TypeLoadException(message, ex);
            }

            if (baseType == null)
            {
                return(allTypesInAssembly);
            }

            return(GetFilteredTypes(allTypesInAssembly, baseType));
        }
コード例 #2
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)));
        }
コード例 #3
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));
        }
コード例 #4
0
 public AssemblyWebResources(_Assembly resourcesAssembly)
 {
     _ResourcesAssembly = resourcesAssembly;
     _WebSiteRoot       = _ResourcesAssembly.GetName().Name;
 }