Skip to content

Commit

Permalink
Type creation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
m-sadegh-sh committed Sep 29, 2024
1 parent b023db0 commit ad201a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions Mvvm/RenderAbstractions/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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[] {
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Zebble/Zebble.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RootNamespace>Zebble</RootNamespace>
<PackageId>Zebble</PackageId>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<Version>5.1.2.0</Version>
<Version>5.1.3.0</Version>
<PackOnBuild>true</PackOnBuild>
<NeutralLanguage>en</NeutralLanguage>
<NoWarn>0618;0162</NoWarn>
Expand Down

0 comments on commit ad201a3

Please sign in to comment.