diff --git a/Mvvm/RenderAbstractions/Templates.cs b/Mvvm/RenderAbstractions/Templates.cs index 14e92a6..63489a3 100644 --- a/Mvvm/RenderAbstractions/Templates.cs +++ b/Mvvm/RenderAbstractions/Templates.cs @@ -16,6 +16,7 @@ public static void Register(Assembly assembly) var viewTypeInfoes = assembly.DefinedTypes .Where(baseViewTypeInfo.IsAssignableFrom) .Where(x => x.ImplementedInterfaces.OrEmpty().Contains(typeof(ITemplate))) + .Except(x => x.IsAbstract) .ToArray(); FromViewsToViewModels(); @@ -50,9 +51,9 @@ void FromViewModelsToGenericViews() .Select(x => new { ViewType = x, - ParentViewModels = x.GetGenericArguments().FirstOrDefault()?.GetParentTypes().Take(2) + ParentViewModel = x.GetGenericArguments().FirstOrDefault()?.GetParentTypes().FirstOrDefault() }) - .Where(x => x.ParentViewModels.HasAny()) + .Except(x => x.ParentViewModel is null) .ToArray(); var baseScreenTypeInfoes = new Type[] { @@ -63,22 +64,17 @@ void FromViewModelsToGenericViews() var screenTypeInfoes = assembly.DefinedTypes .Where(x => baseScreenTypeInfoes.Any(ti => ti.IsAssignableFrom(x))) .Except(x => x.IsAbstract) + .Except(Mappings.ContainsKey) .ToArray(); foreach (var screenTypeInfo in screenTypeInfoes) { - if (Mappings.ContainsKey(screenTypeInfo)) - { - continue; - } - foreach (var screenBaseType in screenTypeInfo.GetParentTypes()) { - var matchedTypeInfo = genericViewTypeInfoes.FirstOrDefault(x => x.ParentViewModels.Contains(screenBaseType)); + var matchedTypeInfo = genericViewTypeInfoes.FirstOrDefault(x => x.ParentViewModel == screenBaseType); if (matchedTypeInfo is not null) { - try { TryRegister(screenTypeInfo, matchedTypeInfo.ViewType.MakeGenericType(screenTypeInfo)); } - catch (ArgumentException) {/* Ignore */} + TryRegister(screenTypeInfo, matchedTypeInfo.ViewType.MakeGenericType(screenTypeInfo)); break; } } diff --git a/Zebble/Zebble.csproj b/Zebble/Zebble.csproj index 0eaa474..0ab2b50 100644 --- a/Zebble/Zebble.csproj +++ b/Zebble/Zebble.csproj @@ -6,7 +6,7 @@ Zebble Zebble $(AssemblyName) ($(TargetFramework)) - 5.1.2.0 + 5.1.3.0 true en 0618;0162