using Connected; namespace Connected.ServiceModel; public static class ServiceModelExtensions { public static List 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(); var baseInterfaces = new List(); 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; } }