public static void AddDetectors(Assembly asm = null, FormatCategories category = FormatCategories.All) { if (asm == null) { asm = Assembly.Load(new AssemblyName("Daramee.FileTypeDetector")); } TypeInfo detectorTypeInfo = typeof(IDetector).GetTypeInfo(); foreach (var type in asm.DefinedTypes) { if (detectorTypeInfo.IsAssignableFrom(type) && !type.IsAbstract && type.DeclaredConstructors.First().GetParameters().Length == 0) { if (category != FormatCategories.All) { bool found = false; foreach (var fc in type.GetCustomAttributes <FormatCategoryAttribute> ()) { if (fc.Category.HasFlag(category)) { found = true; break; } } if (!found) { continue; } } AddDetector(Activator.CreateInstance(type.AsType()) as IDetector); } } }
public FormatCategoryAttribute(FormatCategories category) { Category = category; }