Ejemplo n.º 1
0
        private IList <Tuple <string, Assembly> > GetAllAssemblies()
        {
            Dictionary <string, Tuple <string, Assembly> > assemblies = new Dictionary <string, Tuple <string, Assembly> >();
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            string   path    = Path.GetDirectoryName(executingAssembly.Location);
            Helpers  helpers = new Helpers();

            if (helpers.IsRunningAsUwp())
            {
                path = Directory.GetParent(path).FullName;
            }
#if NETCOREAPP
            var files = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);
#else
            var files = Directory.GetFiles(path, "*.exe", SearchOption.AllDirectories);
#endif
            foreach (string file in files)
            {
                if (executingAssembly.Location.Equals(file))
                {
                    continue;
                }
#if NETCOREAPP
                if (!File.Exists(Path.ChangeExtension(file, "exe")))
                {
                    continue;
                }
#endif
                Assembly assembly  = Assembly.LoadFile(file);
                var      attribute = (AssemblyTitleAttribute)assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false).FirstOrDefault();
                var      name      = attribute?.Title ?? assembly.GetName().Name;
                if (!assemblies.ContainsKey(name))
                {
                    assemblies.Add(name, new Tuple <string, Assembly>(name, assembly));
                }
            }
            return(assemblies.Values.ToList());
        }