private IMvxViewModel LoadViewModel(MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) { IMvxViewModel viewModel = null; var parameterValues = new MvxBundle(request.ParameterValues); try { viewModel = viewModelLocator.Load(request.ViewModelType, parameterValues, savedState); } catch (Exception exception) { throw exception.MvxWrap( "Failed to construct and initialize ViewModel for type {0} from locator {1} - check InnerException for more information", request.ViewModelType, viewModelLocator.GetType().Name); } return(viewModel); }
public IMvxViewModel ReloadViewModel <TParameter>(IMvxViewModel <TParameter> viewModel, TParameter param, MvxViewModelRequest request, IMvxBundle savedState) { var viewModelLocator = FindViewModelLocator(request); var parameterValues = new MvxBundle(request.ParameterValues); try { viewModel = viewModelLocator.Reload(viewModel, param, parameterValues, savedState); } catch (Exception exception) { throw exception.MvxWrap( "Failed to reload a previously created created ViewModel for type {0} from locator {1} - check InnerException for more information", request.ViewModelType, viewModelLocator.GetType().Name); } return(viewModel); }
private IMvxViewModel ReloadViewModel(IMvxViewModel viewModel, MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) { if (viewModelLocator == null) { throw new MvxException("Received view model is null, view model reload failed. ", request.ViewModelType); } var parameterValues = new MvxBundle(request.ParameterValues); try { viewModel = viewModelLocator.Reload(viewModel, parameterValues, savedState); } catch (Exception exception) { throw exception.MvxWrap( "Failed to reload a previously created created ViewModel for type {0} from locator {1} - check InnerException for more information", request.ViewModelType, viewModelLocator.GetType().Name); } return(viewModel); }
public static IMvxBundle SaveStateBundle(this IMvxViewModel viewModel) { var toReturn = new MvxBundle(); var methods = viewModel.GetType() .GetMethods() .Where(m => m.Name == "SaveState") .Where(m => m.ReturnType != typeof(void)) .Where(m => !m.GetParameters().Any()); foreach (var methodInfo in methods) { // use methods like `public T SaveState()` var stateObject = methodInfo.Invoke(viewModel, new object[0]); if (stateObject != null) { toReturn.Write(stateObject); } } // call the general `public void SaveState(bundle)` method too viewModel.SaveState(toReturn); return(toReturn); }
public IMvxViewModel LoadViewModel <TParameter>(MvxViewModelRequest request, TParameter param, IMvxBundle savedState) { if (request.ViewModelType == typeof(MvxNullViewModel)) { return(new MvxNullViewModel()); } var viewModelLocator = FindViewModelLocator(request); IMvxViewModel <TParameter> viewModel = null; var parameterValues = new MvxBundle(request.ParameterValues); try { viewModel = viewModelLocator.Load(request.ViewModelType, param, parameterValues, savedState); } catch (Exception exception) { throw exception.MvxWrap( "Failed to construct and initialize ViewModel for type {0} from locator {1} - check InnerException for more information", request.ViewModelType, viewModelLocator.GetType().Name); } return(viewModel); }
protected MvxPresentationHint(MvxBundle body) { Body = body; }