Beispiel #1
0
 IEnumerable <Type> LoadPluginAssembly(System.Reflection.Assembly asm)
 {
     try {
         var res = asm.GetTypes()
                   .Where(type => type.GetCustomAttributes(typeof(PluginAttribute), true).Length > 0)
                   .Where(type => type.GetInterfaces().Contains(typeof(IPlugin)));
         foreach (var settingtype in asm.GetTypes().Where(type => type.GetCustomAttributes(typeof(PecaSettingsAttribute), true).Length > 0))
         {
             foreach (var attr in settingtype.GetCustomAttributes(typeof(PecaSettingsAttribute), true).Cast <PecaSettingsAttribute>())
             {
                 if (attr.Alias != null)
                 {
                     PecaSettings.RegisterType(attr.Alias, settingtype);
                 }
                 else
                 {
                     PecaSettings.RegisterType(settingtype.FullName, settingtype);
                 }
             }
         }
         foreach (var enumtype in asm.GetTypes().Where(type => type.IsEnum && type.IsPublic && !type.IsNested))
         {
             PecaSettings.RegisterType(enumtype.FullName, enumtype);
         }
         return(res);
     }
     catch (BadImageFormatException) {
         return(Enumerable.Empty <Type>());
     }
     catch (System.Reflection.ReflectionTypeLoadException) {
         return(Enumerable.Empty <Type>());
     }
 }
Beispiel #2
0
 IEnumerable <Type> LoadPluginAssembly(System.Reflection.Assembly asm)
 {
     try {
         var res = asm.GetTypes()
                   .Where(type => type.GetCustomAttributes(typeof(PluginAttribute), true).Length > 0)
                   .Where(type => type.GetInterfaces().Contains(typeof(IPlugin)))
                   .OrderBy(type => ((PluginAttribute)(type.GetCustomAttributes(typeof(PluginAttribute), true)[0])).Priority);
         foreach (var settingtype in asm.GetTypes().Where(type => type.GetCustomAttributes(typeof(PecaSettingsAttribute), true).Length > 0))
         {
             PecaSettings.RegisterType(settingtype);
         }
         return(res);
     }
     catch (System.Reflection.ReflectionTypeLoadException) {
         return(Enumerable.Empty <Type>());
     }
 }