Skip to content

Commit

Permalink
Merge pull request #84 from simplic/AssemblyException
Browse files Browse the repository at this point in the history
Add exception for load assemblies.
  • Loading branch information
jogibear9988 committed Jan 6, 2022
2 parents 1e1a4ec + dc96001 commit d089d65
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,20 @@ public void LoadItemsCombobox()

private IEnumerable<Type> GetInheritedClasses(Type type)
{
return AppDomain.CurrentDomain.GetAssemblies().Where(x => !x.IsDynamic).SelectMany(x => x.GetTypes().Where(y => y.IsClass && !y.IsAbstract && y.IsSubclassOf(type)));
return AppDomain.CurrentDomain.GetAssemblies().Where(x => !x.IsDynamic).SelectMany(x => GetLoadableTypes(x).Where(y => y.IsClass && !y.IsAbstract && y.IsSubclassOf(type)));
}

private IEnumerable<Type> GetLoadableTypes(Assembly assembly)
{
if (assembly == null) throw new ArgumentNullException("assembly");
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
return e.Types.Where(t => t != null);
}
}

private void OnAddItemClicked(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit d089d65

Please sign in to comment.