changement de candidat à l'investissement
This commit is contained in:
parent
8114c2409c
commit
be3087fff6
351 changed files with 359 additions and 497 deletions
58
ZicMoove/ZicMoove/Factories/ViewFactory.cs
Normal file
58
ZicMoove/ZicMoove/Factories/ViewFactory.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using BookAStar.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace BookAStar.Factories
|
||||
{
|
||||
public class ViewFactory : IViewFactory
|
||||
{
|
||||
private readonly IDictionary<Type, Type> _map = new Dictionary<Type, Type>();
|
||||
private readonly IComponentContext _componentContext;
|
||||
|
||||
public ViewFactory(IComponentContext componentContext)
|
||||
{
|
||||
_componentContext = componentContext;
|
||||
}
|
||||
|
||||
public void Register<TViewModel, TView>()
|
||||
where TViewModel : class, IModelViewModel
|
||||
where TView : Page
|
||||
{
|
||||
_map[typeof(TViewModel)] = typeof(TView);
|
||||
}
|
||||
|
||||
public Page Resolve<TViewModel>(Action<TViewModel> setStateAction = null) where TViewModel : class, IModelViewModel
|
||||
{
|
||||
TViewModel viewModel;
|
||||
return Resolve<TViewModel>(out viewModel, setStateAction) ;
|
||||
}
|
||||
|
||||
public Page Resolve<TViewModel>(out TViewModel viewModel, Action<TViewModel> setStateAction = null)
|
||||
where TViewModel : class, IModelViewModel
|
||||
{
|
||||
viewModel = _componentContext.Resolve<TViewModel>();
|
||||
|
||||
var viewType = _map[typeof(TViewModel)];
|
||||
var view = _componentContext.Resolve(viewType) as Page;
|
||||
|
||||
if (setStateAction != null)
|
||||
viewModel.SetState(setStateAction);
|
||||
|
||||
view.BindingContext = viewModel;
|
||||
return view;
|
||||
}
|
||||
|
||||
public Page Resolve<TViewModel>(TViewModel viewModel)
|
||||
where TViewModel : class, IModelViewModel
|
||||
{
|
||||
var viewType = _map[typeof(TViewModel)];
|
||||
var view = _componentContext.Resolve(viewType) as Page;
|
||||
view.BindingContext = viewModel;
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue