mirror of
https://github.com/BlossomiShymae/Needlework.Net.git
synced 2026-07-12 05:59:42 +02:00
refactor: page factory and less mvvm-breaking
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Needlework.Net.ViewModels.Pages
|
||||
{
|
||||
public class PageFactory
|
||||
{
|
||||
private readonly IEnumerable<PageBase> _pages;
|
||||
|
||||
public PageFactory(IEnumerable<PageBase> pages)
|
||||
{
|
||||
_pages = pages;
|
||||
}
|
||||
|
||||
public PageBase GetPage<T>() where T : PageBase
|
||||
{
|
||||
var page = _pages.Where(page => typeof(T) == page.GetType())
|
||||
.FirstOrDefault() ?? throw new NotSupportedException(typeof(T).FullName);
|
||||
Task.Run(page.InitializeAsync);
|
||||
return page;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user