Skip to content

Commit

Permalink
IocPage again
Browse files Browse the repository at this point in the history
  • Loading branch information
Simnico99 committed Sep 15, 2022
1 parent c45e8af commit 1b4c78b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
[AttributeUsage(AttributeTargets.Class)]
public sealed class PageDataContextAttribute : Attribute
{
public Type[] PagesToBindType { get; }
public Type[]? PagesToBindType { get; }
public PageDataContextAttribute() { }

public PageDataContextAttribute(params Type[] pagesToBind)
{
if (pagesToBind.Length <= 0)
{
PagesToBindType = Array.Empty<Type>();
PagesToBindType = null;
}

PagesToBindType = pagesToBind;
Expand Down
4 changes: 2 additions & 2 deletions src/ZirconNet.WPF/Mvvm/IocPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private IEnumerable<ViewModel> GetPagesDataContextInternal(IServiceProvider serv
}

var viewModel = (ViewModel?)servicesProvider.GetService(service.ServiceType);
var attribute = viewModel?.GetType().GetCustomAttribute<PageDataContextAttribute>();
var attribute = service.ServiceType.GetType().GetCustomAttribute<PageDataContextAttribute>();

if (attribute is not (not null and PageDataContextAttribute pageDataContextAttribute))
{
Expand All @@ -46,7 +46,7 @@ private IEnumerable<ViewModel> GetPagesDataContextInternal(IServiceProvider serv
continue;
}

if (pageDataContextAttribute.PagesToBindType.Length <= 0)
if (pageDataContextAttribute.PagesToBindType is null || pageDataContextAttribute.PagesToBindType.Length <= 0)
{
yield return viewModel;
continue;
Expand Down

0 comments on commit 1b4c78b

Please sign in to comment.