using System.Reflection; using Connected.Annotations; using Connected.Services.Middleware; namespace Connected.Services; public static class ServicesExtensions { public static List GetImplementedServices(this Type type) { var result = new List(); var interfaces = type.GetInterfaces(); foreach (var i in interfaces) { if (i.GetCustomAttribute() 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() 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); } }