/// <summary> /// Wraps the specified view-model to a specified type. /// </summary> /// <param name="viewModel">The specified view-model.</param> /// <param name="wrapperType">The specified type to wrap.</param> /// <param name="dataContext">The specified <see cref="IDataContext" />, if any.</param> /// <returns> /// An instance of <see cref="IViewModel" />. /// </returns> public IViewModel Wrap(IViewModel viewModel, Type wrapperType, IDataContext dataContext) { Should.NotBeNull(viewModel, "viewModel"); Should.NotBeNull(wrapperType, "wrapperType"); List <WrapperRegistration> list; if (_registrations.TryGetValue(wrapperType, out list)) { for (int i = 0; i < list.Count; i++) { WrapperRegistration registration = list[i]; if (registration.Condition(viewModel, dataContext)) { return(WrapInternal(viewModel, registration.Type, dataContext)); } } } var wrapper = WrapToDefaultWrapper(viewModel, wrapperType, dataContext); if (wrapper == null) { throw ExceptionManager.WrapperTypeNotSupported(wrapperType); } return(wrapper); }
public WeakReferenceableWrapper(IntPtr instance, WrapperRegistration reg) { var inst = Marshal.PtrToStructure <VtblPtr>(instance); this.vtable = Marshal.PtrToStructure <Vtbl>(inst.Vtbl); this.instance = instance; Registration = reg; }
/// <summary> /// Creates the wrapper view model. /// </summary> protected override object WrapInternal(object item, WrapperRegistration wrapperRegistration, IDataContext dataContext) { object result = base.WrapInternal(item, wrapperRegistration, dataContext); //Changing default wrapper view to TabbedPage. if (item is OrderEditorViewModel) ((IViewModel) result).Settings.Metadata.Add(NavigationConstants.ViewName, OrderViewName); return result; }
/// <summary> /// Creates the wrapper view model. /// </summary> protected override object WrapInternal(object item, WrapperRegistration wrapperRegistration, IDataContext dataContext) { object result = base.WrapInternal(item, wrapperRegistration, dataContext); //Changing default wrapper view to TabbedPage. if (item is OrderEditorViewModel) { ((IViewModel)result).Settings.Metadata.Add(NavigationConstants.ViewName, OrderViewName); } return(result); }
protected virtual object WrapInternal(object item, WrapperRegistration wrapperRegistration, IDataContext dataContext) { if (wrapperRegistration.WrapperFactory != null) { return(wrapperRegistration.WrapperFactory(item, dataContext)); } var wrapperType = wrapperRegistration.Type; #if PCL_WINRT if (wrapperType.GetTypeInfo().IsGenericTypeDefinition) #else if (wrapperType.IsGenericTypeDefinition) #endif { wrapperType = wrapperType.MakeGenericType(item.GetType()); } var viewModel = item as IViewModel; if (viewModel != null && typeof(IWrapperViewModel).IsAssignableFrom(wrapperType)) { dataContext = dataContext.ToNonReadOnly(); if (!dataContext.Contains(InitializationConstants.ParentViewModel)) { var parentViewModel = viewModel.GetParentViewModel(); if (parentViewModel != null) { dataContext.AddOrUpdate(InitializationConstants.ParentViewModel, parentViewModel); } } var vm = (IWrapperViewModel)_viewModelProvider.GetViewModel(wrapperType, dataContext); vm.Wrap(viewModel, dataContext); return(vm); } #if PCL_WINRT var constructor = wrapperType.GetTypeInfo() .DeclaredConstructors .FirstOrDefault(info => !info.IsStatic); #else var constructor = wrapperType .GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic) .FirstOrDefault(); #endif if (constructor == null) { return(null); } return(constructor.InvokeEx(item)); }
public object Wrap(object item, Type wrapperType, IDataContext dataContext) { Should.NotBeNull(item, "item"); Should.NotBeNull(wrapperType, "wrapperType"); if (wrapperType.IsInstanceOfType(item)) { return(item); } dataContext = dataContext.ToNonReadOnly(); object wrapper = null; List <WrapperRegistration> list; if (_registrations.TryGetValue(wrapperType, out list)) { dataContext.AddOrUpdate(ItemToWrapConstant, item); var type = item.GetType(); for (int i = 0; i < list.Count; i++) { WrapperRegistration registration = list[i]; if (registration.Condition(type, dataContext)) { wrapper = WrapInternal(item, registration, dataContext); } } dataContext.Remove(ItemToWrapConstant); } if (wrapper == null) { wrapper = WrapToDefaultWrapper(item, wrapperType, dataContext); } if (wrapper == null) { throw ExceptionManager.WrapperTypeNotSupported(wrapperType); } return(wrapper); }
public TestComWrappers(WrapperRegistration reg = WrapperRegistration.Local) { Registration = reg; }