-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewCache.cs
More file actions
28 lines (26 loc) · 943 Bytes
/
ViewCache.cs
File metadata and controls
28 lines (26 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Collections.Generic;
using System.Linq;
using Client.MVVM.Base.ViewModel.Contexts;
using Client.RaidApp;
using Client.ViewModel.DTO;
namespace Raid.Toolkit.Community.Extensibility.ViewModel
{
public class ViewCache
{
private readonly Dictionary<ViewKey, List<IContext>> Views;
public ViewCache(RaidViewMaster viewMaster)
{
Views = viewMaster._views.GroupBy(viewMeta => viewMeta.Key, viewMeta => viewMeta.View.Context).ToDictionary(kvp => kvp.Key, kvp => kvp.ToList());
}
public bool TryGetViewContext<T>(ViewKey viewKey, out T? viewContext) where T : class, IContext
{
if (!Views.TryGetValue(viewKey, out List<IContext>? contexts))
{
viewContext = null;
return false;
}
viewContext = contexts.OfType<T>().FirstOrDefault();
return viewContext != null;
}
}
}