public DefaultApp(Type startViewModelType, LoadMode mode = LoadMode.Runtime) : base(mode) { Should.NotBeNull(startViewModelType, nameof(startViewModelType)); Should.BeOfType <IViewModel>(startViewModelType, "startViewModelType"); _startViewModelType = startViewModelType; }
protected override SynchronizedNotifiableCollection <T> CreateNotifiableCollection <T>(ExecutionMode executionMode, IThreadManager threadManager) { Should.BeOfType(typeof(Item), "type", typeof(T)); return ((SynchronizedNotifiableCollection <T>)(object) CreateNotifiableCollection(executionMode, threadManager)); }
/// <summary> /// Initializes a new instance of the <see cref="ViewModelAttribute" /> class. /// </summary> /// <param name="viewModelType">The specified type of view model.</param> /// <param name="name">The name of view mapping</param> public ViewModelAttribute([NotNull, ViewModelTypeRequired] Type viewModelType, string name = null) { Should.NotBeNull(viewModelType, "viewModelType"); Should.BeOfType <IViewModel>(viewModelType, "viewModelType"); _viewModelType = viewModelType; _name = name; }
public DefaultApp(Type startViewModelType, LoadMode mode = LoadMode.Runtime, IList <IModule> modules = null, Action <IModuleContext> loadModulesDelegate = null) : base(mode, modules, loadModulesDelegate) { Should.NotBeNull(startViewModelType, nameof(startViewModelType)); Should.BeOfType <IViewModel>(startViewModelType, "startViewModelType"); _startViewModelType = startViewModelType; }
public DefaultApp(Type startViewModelType, IViewModelSettings viewModelSettings = null, LoadMode mode = LoadMode.Runtime) : base(mode) { Should.NotBeNull(startViewModelType, "startViewModelType"); Should.BeOfType <IViewModel>(startViewModelType, "startViewModelType"); _startViewModelType = startViewModelType; _viewModelSettings = viewModelSettings; }
public ViewMappingItem(Type viewModelType, Type viewType, string name, Uri uri) { Should.BeOfType <IViewModel>(viewModelType, "viewModelType"); Should.NotBeNull(viewType, "viewType"); _viewModelType = viewModelType; _viewType = viewType; _name = name; _uri = uri ?? Empty; }
public static FragmentManager GetFragmentManager(this Activity activity) { Should.NotBeNull(activity, nameof(activity)); #if APPCOMPAT Should.BeOfType <FragmentActivity>(activity, "activity"); return(((FragmentActivity)activity).SupportFragmentManager); #else return(activity.FragmentManager); #endif }
/// <summary> /// Gets a delegate to call the specified <see cref="MethodInfo" />. /// </summary> /// <param name="delegateType">The type of delegate.</param> /// <param name="method"> /// The specified <see cref="MethodInfo" /> /// </param> /// <returns> /// An instance of delegate. /// </returns> public virtual Delegate GetMethodDelegate(Type delegateType, MethodInfo method) { Should.NotBeNull(delegateType, "delegateType"); Should.BeOfType <Delegate>(delegateType, "delegateType"); Should.NotBeNull(method, "method"); lock (InvokeMethodCacheDelegate) { var cacheKey = new MethodDelegateCacheKey(method, delegateType); Delegate value; if (!InvokeMethodCacheDelegate.TryGetValue(cacheKey, out value)) { MethodInfo delegateMethod = delegateType.GetMethodEx("Invoke"); var delegateParams = delegateMethod.GetParameters().ToList(); ParameterInfo[] methodParams = method.GetParameters(); var expressions = new List <Expression>(); var parameters = new List <ParameterExpression>(); if (!method.IsStatic) { var thisParam = Expression.Parameter(delegateParams[0].ParameterType, "@this"); parameters.Add(thisParam); expressions.Add(ConvertIfNeed(thisParam, GetDeclaringType(method), false)); delegateParams.RemoveAt(0); } Should.BeValid("delegateType", delegateParams.Count == methodParams.Length); for (int i = 0; i < methodParams.Length; i++) { ParameterExpression parameter = Expression.Parameter(delegateParams[i].ParameterType, i.ToString()); parameters.Add(parameter); expressions.Add(ConvertIfNeed(parameter, methodParams[i].ParameterType, false)); } Expression callExpression; if (method.IsStatic) { callExpression = Expression.Call(null, method, expressions.ToArrayEx()); } else { Expression @this = expressions[0]; expressions.RemoveAt(0); callExpression = Expression.Call(@this, method, expressions.ToArrayEx()); } if (delegateMethod.ReturnType != typeof(void)) { callExpression = ConvertIfNeed(callExpression, delegateMethod.ReturnType, false); } var lambdaExpression = CreateLambdaExpressionByType(delegateType, callExpression, parameters); value = lambdaExpression.Compile(); InvokeMethodCacheDelegate[cacheKey] = value; } return(value); } }
public static ActionMode StartActionMode(this ActionBar actionBar, ActionMode.ICallback mode) { var activity = actionBar.ThemedContext.GetActivity(); #if APPCOMPAT Should.BeOfType <AppCompatActivity>(activity, "Activity"); return(((AppCompatActivity)activity).StartSupportActionMode(mode)); #else Should.NotBeNull(activity, "activity"); return(activity.StartActionMode(mode)); #endif }
public MultiViewModel() { var collection = new SynchronizedNotifiableCollection <IViewModel>(); var list = ServiceProvider.TryDecorate(collection); Should.BeOfType <INotifiableCollection <IViewModel> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <IViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _weakEventHandler = ReflectionExtensions.CreateWeakDelegate <MultiViewModel, ViewModelClosedEventArgs, EventHandler <ICloseableViewModel, ViewModelClosedEventArgs> >(this, (model, o, arg3) => model.ItemsSource.Remove(arg3.ViewModel), UnsubscribeAction, handler => handler.Handle); _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); DisposeViewModelOnRemove = true; }
public static ActionBar GetActionBar(this Activity activity, bool throwOnError = true) { Should.NotBeNull(activity, nameof(activity)); #if APPCOMPAT if (throwOnError) { Should.BeOfType <AppCompatActivity>(activity, "activity"); return(((AppCompatActivity)activity).SupportActionBar); } return((activity as AppCompatActivity)?.SupportActionBar); #else return(activity.ActionBar); #endif }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } Should.BeOfType <Visibility>(value, "value"); if (_trueValue.Equals(value)) { return(Empty.TrueObject); } if (_falseValue.Equals(value)) { return(Empty.FalseObject); } return(null); }
public IViewMappingItem FindMappingForViewModel(Type viewModelType, string viewName, bool throwOnError) { Should.BeOfType <IViewModel>(viewModelType, "viewModelType"); EnsureInitialized(); viewName = viewName ?? string.Empty; Dictionary <string, IViewMappingItem> value; if (!_viewModelToMapping.TryGetValue(viewModelType, out value)) { #if NET_STANDARD if (viewModelType.GetTypeInfo().IsGenericType) #else if (viewModelType.IsGenericType) #endif { viewModelType = viewModelType.GetGenericTypeDefinition(); if (viewModelType != null) { _viewModelToMapping.TryGetValue(viewModelType, out value); } } } if (value == null) { if (throwOnError) { throw ExceptionManager.ViewNotFound(viewModelType); } return(null); } IViewMappingItem item; if (!value.TryGetValue(viewName, out item)) { if (viewName != string.Empty) { value.TryGetValue(string.Empty, out item); } } if (item == null && throwOnError) { throw ExceptionManager.ViewNotFound(viewModelType); } return(item); }
public MultiViewModel() { var collection = new SynchronizedNotifiableCollection <TViewModel>(); var list = ServiceProvider.TryDecorate(this, collection); Should.BeOfType <INotifiableCollection <TViewModel> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <TViewModel>)list; collection.AfterCollectionChanged = OnViewModelsChanged; _propertyChangedWeakEventHandler = ReflectionExtensions.MakeWeakPropertyChangedHandler(this, (model, o, arg3) => model.OnItemPropertyChanged(o, arg3)); var weakReference = ToolkitExtensions.GetWeakReference(this); _closeViewModelWeakHandler = (dispatcher, vm, arg3) => { var self = (MultiViewModel <TViewModel>)weakReference.Target; return(self?.CloseViewModel(dispatcher, vm, arg3) ?? Empty.FalseTask); }; DisposeViewModelOnRemove = ApplicationSettings.MultiViewModelDisposeViewModelOnRemove; CloseViewModelsOnClose = ApplicationSettings.MultiViewModelCloseViewModelsOnClose; }
public void SetOriginalItemsSource <TItemsSource>(TItemsSource originalItemsSource) where TItemsSource : IList <T>, INotifyCollectionChanged, IList { EnsureNotDisposed(); Should.NotBeNull(originalItemsSource, "originalItemsSource"); lock (_weakPropertyHandler) { INotifyCollectionChanging collectionChanging; if (_originalData != null) { collectionChanging = _originalData as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging -= RaiseCollectionChanging; } ((INotifyCollectionChanged)(_originalData)).CollectionChanged -= RaiseCollectionChanged; if (_originalData.Count != 0) { originalItemsSource.AddRange(_originalData); } } _filterableItemsSource = new FilterableNotifiableCollection <T>(originalItemsSource); collectionChanging = originalItemsSource as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging += RaiseCollectionChanging; } originalItemsSource.CollectionChanged += RaiseCollectionChanged; _originalData = originalItemsSource; var list = ServiceProvider.TryDecorate(FilterableItemsSource); Should.BeOfType <INotifiableCollection <T> >(list, "DecoratedItemsSource"); Should.BeOfType <INotifiableCollection>(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <T>)list; } UpdateFilter(); OnPropertyChanged("ItemsSource"); OnPropertyChanged("OriginalItemsSource"); }
public void SetOriginalItemsSource <TItemsSource>(TItemsSource originalItemsSource) where TItemsSource : IList <T>, INotifyCollectionChanged, IList { EnsureNotDisposed(); Should.NotBeNull(originalItemsSource, nameof(originalItemsSource)); INotifyCollectionChanging collectionChanging; if (_originalData != null) { collectionChanging = _originalData as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging -= RaiseCollectionChanging; } ((INotifyCollectionChanged)_originalData).CollectionChanged -= RaiseCollectionChanged; if (_originalData.Count != 0) { originalItemsSource.AddRange(_originalData, true); } } _filterableItemsSource = new FilterableNotifiableCollection <T>(originalItemsSource); collectionChanging = originalItemsSource as INotifyCollectionChanging; if (collectionChanging != null) { collectionChanging.CollectionChanging += RaiseCollectionChanging; } originalItemsSource.CollectionChanged += RaiseCollectionChanged; _originalData = originalItemsSource; var list = ToolkitServiceProvider.TryDecorate(this, FilterableItemsSource); Should.BeOfType <INotifiableCollection <T> >(list, "DecoratedItemsSource"); _itemsSource = (INotifiableCollection <T>)list; UpdateFilter(); OnPropertyChanged(nameof(ItemsSource)); OnPropertyChanged(nameof(OriginalItemsSource)); RaiseItemsSourceChanged(_itemsSource); }
/// <summary> /// Shows the view in the specified mode. /// </summary> protected override void ShowView(IWindowView view, bool isDialog, IDataContext context) { var navigationProvider = ViewModel.GetIocContainer(true).Get <INavigationProvider>(); view.Cancelable = !isDialog; FragmentManager fragmentManager = null; var parentViewModel = ViewModel.GetParentViewModel(); if (parentViewModel != null) { var fragment = parentViewModel.Settings.Metadata.GetData(ViewModelConstants.View) as Fragment; if (fragment != null) { fragmentManager = fragment.ChildFragmentManager; } } if (fragmentManager == null) { Should.BeOfType <Activity>(navigationProvider.CurrentContent, "Activity"); var activity = (Activity)navigationProvider.CurrentContent; fragmentManager = activity.GetFragmentManager(); } view.Show(fragmentManager, Guid.NewGuid().ToString("n")); }
public void Register(Type validatorType) { Should.BeOfType <IValidator>(validatorType, "validatorType"); lock (_validators) _validators[validatorType] = GetSupportedType(validatorType); }
protected override ICollection <T> CreateCollection <T>(params T[] items) { Should.BeOfType(typeof(Item), "type", typeof(T)); return((ICollection <T>)CreateNotifiableCollection(ExecutionMode.None, null, items.OfType <Item>())); }
public BootstrapperAttribute([NotNull] Type bootstrapperType) { Should.BeOfType <AndroidBootstrapperBase>(bootstrapperType, "bootstrapperType"); _bootstrapperType = bootstrapperType; }
public static BindingInfo <T> FromType(Type serviceType, DependencyLifecycle lifecycle, string name = null, params IIocParameter[] parameters) { Should.NotBeNull(serviceType, "serviceType"); Should.BeOfType <T>(serviceType, "serviceType"); return(new BindingInfo <T>(serviceType, null, default(T), lifecycle, name, parameters)); }
public BootstrapperAttribute([NotNull] Type bootstrapperType, int priority = 0) { Should.BeOfType <AndroidBootstrapperBase>(bootstrapperType, "bootstrapperType"); _bootstrapperType = bootstrapperType; _priority = priority; }
public bool Unregister(Type validatorType) { Should.BeOfType <IValidator>(validatorType, "validatorType"); lock (_validators) return(_validators.Remove(validatorType)); }
public bool IsRegistered(Type validatorType) { Should.BeOfType <IValidator>(validatorType, "validatorType"); lock (_validators) return(_validators.ContainsKey(validatorType)); }