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.
Connected.Framework/Connected.Runtime/ServiceModelExtensions.cs

51 lines
1.2 KiB

using Connected;
namespace Connected.ServiceModel;
public static class ServiceModelExtensions
{
public static List<Type> GetImplementedArguments(this Type type)
{
/*
* Only direct implementation is used so we can eliminate multiple implementations
* and thus resolving wrong arguments when mapping request.
*/
var interfaces = type.GetInterfaces();
var allInterfaces = new List<Type>();
var baseInterfaces = new List<Type>();
foreach (var i in interfaces)
{
if (typeof(IDto)?.FullName is not string fullName)
continue;
if (i.GetInterface(fullName) is null)
continue;
if (i == typeof(IDto))
continue;
allInterfaces.Add(i);
foreach (var baseInterface in i.GetInterfaces())
{
if (baseInterface == typeof(IDto) || typeof(IDto)?.FullName is not string baseFullName)
continue;
if (baseInterface.GetInterface(baseFullName) is not null)
baseInterfaces.Add(baseInterface);
}
}
return allInterfaces.Except(baseInterfaces).ToList();
}
public static bool IsArgumentImplementation(this Type type)
{
if (typeof(IDto)?.FullName is not string fullName)
return false;
return !type.IsInterface && !type.IsAbstract && type.GetInterface(fullName) is not null;
}
}