Esempio n. 1
0
 private static IEnumerable <Type> TypesImplementingInterface(Assembly assembly, Type desiredType)
 {
     return(Enumerable.Where <Type>((IEnumerable <Type>)assembly.GetTypes(), (Func <Type, bool>)(type =>
     {
         if (desiredType.IsAssignableFrom(type))
         {
             return SubtitleDownloaderFactory.IsRealClass(type);
         }
         return false;
     })));
 }
Esempio n. 2
0
 static SubtitleDownloaderFactory()
 {
     try
     {
         SubtitleDownloaderFactory.CreateDownloaderInstances(SubtitleDownloaderFactory.FindDownloaderImplementations());
     }
     catch (ReflectionTypeLoadException ex)
     {
         StringBuilder stringBuilder = new StringBuilder();
         stringBuilder.AppendLine("Following loader exceptions were found: ");
         foreach (Exception exception in ex.LoaderExceptions)
         {
             stringBuilder.AppendLine(exception.Message);
         }
         throw new Exception(stringBuilder.ToString(), (Exception)ex);
     }
 }
Esempio n. 3
0
        private static IEnumerable <Type> FindDownloaderImplementations()
        {
            List <Type> list = new List <Type>();

            list.AddRange(SubtitleDownloaderFactory.TypesImplementingInterface(Assembly.GetExecutingAssembly(), typeof(ISubtitleDownloader)));
            string path1 = FileUtils.AssemblyDirectory + "\\SubtitleDownloaders";

            if (Directory.Exists(path1))
            {
                foreach (string path2 in Enumerable.Where <string>((IEnumerable <string>)Directory.GetFiles(path1), (Func <string, bool>)(s => s.EndsWith("dll"))))
                {
                    try
                    {
                        Assembly assembly = Assembly.LoadFile(path2);
                        list.AddRange(SubtitleDownloaderFactory.TypesImplementingInterface(assembly, typeof(ISubtitleDownloader)));
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            return((IEnumerable <Type>)list);
        }