You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Connected.Annotations;
|
|
|
|
|
using Connected.Services.Middleware;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Services;
|
|
|
|
|
|
|
|
|
|
public static class ServicesExtensions
|
|
|
|
|
{
|
|
|
|
|
public static List<Type> GetImplementedServices(this Type type)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<Type>();
|
|
|
|
|
var interfaces = type.GetInterfaces();
|
|
|
|
|
|
|
|
|
|
foreach (var i in interfaces)
|
|
|
|
|
{
|
|
|
|
|
if (i.GetCustomAttribute<ServiceAttribute>() is not null)
|
|
|
|
|
result.Add(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsService(this Type type)
|
|
|
|
|
{
|
|
|
|
|
var interfaces = type.GetInterfaces();
|
|
|
|
|
|
|
|
|
|
foreach (var i in interfaces)
|
|
|
|
|
{
|
|
|
|
|
if (i.GetCustomAttribute<ServiceAttribute>() is not null)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsServiceMiddleware(this Type type)
|
|
|
|
|
{
|
|
|
|
|
return type.GetInterface(typeof(IServiceMiddleware<>).FullName) is not null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsServiceOperation(this Type type)
|
|
|
|
|
{
|
|
|
|
|
return type.GetInterface(typeof(IServiceOperation<>).FullName) is not null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsServiceFunction(this Type type)
|
|
|
|
|
{
|
|
|
|
|
var nf = typeof(INullableFunction<,>).FullName;
|
|
|
|
|
var f = typeof(IFunction<,>).FullName;
|
|
|
|
|
|
|
|
|
|
return (f is not null && type.GetInterface(f) is not null)
|
|
|
|
|
|| (nf is not null && type.GetInterface(nf) is not null);
|
|
|
|
|
}
|
|
|
|
|
}
|