Skip to content

Commit

Permalink
IocPage
Browse files Browse the repository at this point in the history
  • Loading branch information
Simnico99 committed Sep 16, 2022
1 parent df76f14 commit 0af16eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[AttributeUsage(AttributeTargets.Class)]
public sealed class PageDataContextAttribute : Attribute
{
public IEnumerable<string>? PagesToBindName { get; }
public Type[]? PagesToBindType { get; }
public PageDataContextAttribute() { }

public PageDataContextAttribute(params Type[] pagesToBind)
Expand All @@ -12,6 +12,6 @@ public PageDataContextAttribute(params Type[] pagesToBind)
{
return;
}
PagesToBindName = pagesToBind.Select(x => x.Name).ToList();
PagesToBindType = pagesToBind;
}
}
14 changes: 9 additions & 5 deletions src/ZirconNet.WPF/Mvvm/IocPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ private List<ViewModel> GetPageDataContexts(IServiceProvider servicesProvider, I
continue;
}

if (pageDataContextAttribute.PagesToBindName is null)
if (pageDataContextAttribute.PagesToBindType is null)
{
viewModels.Add(viewModel);
continue;
}
if (pageDataContextAttribute.PagesToBindName.Contains(GetType().Name))
if (pageDataContextAttribute.PagesToBindType.Contains(GetType()))
{
viewModels.Add(viewModel);
}
Expand Down Expand Up @@ -91,14 +91,18 @@ private IEnumerable<ViewModel> GetPageDataContexts(IServiceProvider servicesProv
continue;
}

if (pageDataContextAttribute.PagesToBindName is null)
if (pageDataContextAttribute.PagesToBindType is null)
{
yield return viewModel;
continue;
}
if (pageDataContextAttribute.PagesToBindName.Contains(GetType().Name))
foreach (var type in pageDataContextAttribute.PagesToBindType)
{
yield return viewModel;
if (type == GetType())
{
yield return viewModel;
continue;
}
}
}
#endif
Expand Down

0 comments on commit 0af16eb

Please sign in to comment.