Refactoring
This commit is contained in:
35
Oqtane.Server/Extensions/AssemblyExtensions.cs
Normal file
35
Oqtane.Server/Extensions/AssemblyExtensions.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace System.Reflection
|
||||
{
|
||||
public static class AssemblyExtensions
|
||||
{
|
||||
public static IEnumerable<Type> GetInterfaces<TInterfaceType>(this Assembly assembly)
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
return assembly.GetTypes(typeof(TInterfaceType));
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> GetTypes(this Assembly assembly, Type interfaceType)
|
||||
{
|
||||
if (assembly is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
if (interfaceType is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(interfaceType));
|
||||
}
|
||||
|
||||
return assembly.GetTypes()
|
||||
.Where(t => t.GetInterfaces().Contains(interfaceType));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user