private IMvxViewModel LoadViewModel(MvxViewModelRequest request, IMvxBundle savedState, IMvxViewModelLocator viewModelLocator) { IMvxViewModel viewModel = null; var parameterValues = new MvxBundle(request.ParameterValues); if (!viewModelLocator.TryLoad(request.ViewModelType, parameterValues, savedState, out viewModel)) { throw new MvxException( "Failed to construct and initialize ViewModel for type {0} from locator {1} - check MvxTrace for more information", request.ViewModelType, viewModelLocator.GetType().Name); } viewModel.RequestedBy = request.RequestedBy; return(viewModel); }
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); } viewModel.RequestedBy = request.RequestedBy; 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); }
protected MvxPresentationHint(MvxBundle body) { Body = body; }