/// <inheritdoc /> public IBadRequestProvider ForProperty <TCommand>(Expression <Func <TCommand, object?> > expression) { var propertyName = PropertyExpressionHelper.GetPropertyName(expression); ForProperty(propertyName); return(this); }
/// <summary> /// Gets the error message for the property with the given name. /// </summary> /// <param name="columnName">The name of the property whose error message to get.</param> public string this[string columnName] { get { var nameColumn = PropertyExpressionHelper.GetName <ITermEditViewModel, string>(_ => _.Name); if (nameColumn == columnName) { return(this.Error); } return(String.Empty); } }
/// <summary> /// Initializes a new instance of the <see cref="TermListView"/> class. /// </summary> /// <param name="model">A model to use by a new instance.</param> public TermListView(ITermListViewModel model) { if (model == null) { throw new ArgumentException("model"); } this.Model = model; this.InitializeComponent(); this.SetBinding( TermListView.IsEditModeProperty, new Binding(PropertyExpressionHelper.GetName <ITermListViewModel, bool>(_ => _.IsEditMode))); }
public void ModelSetsErrorWhenTermNameIsWhitespace() { var nameProperty = PropertyExpressionHelper.GetName <ITermEditViewModel, string>(_ => _.Name); var model = new TermEditViewModel(); TermEditViewModelFixture.AssertDataErrorInfo(model, true); model.Name = "term0"; TermEditViewModelFixture.AssertDataErrorInfo(model, false); model.Name = " "; TermEditViewModelFixture.AssertDataErrorInfo(model, true); }
/// <summary> /// Initializes a new instance of the <see cref="TermListViewModel"/> class. /// </summary> /// <param name="termsService">A service that allows to access a storage of glossary terms.</param> /// <param name="editViewModel">A model of a view to edit terms.</param> public TermListViewModel(ITermsService termsService, ITermEditViewModel editViewModel) { if (termsService == null) { throw new ArgumentNullException("termsService"); } if (editViewModel == null) { throw new ArgumentNullException("editViewModel"); } this._termsService = termsService; this.EditViewModel = editViewModel; // Create view of term collection sorted by Name. var termsView = new ListCollectionView(this._terms); termsView.SortDescriptions.Add(new SortDescription( PropertyExpressionHelper.GetName <Term, string>(_ => _.Name), ListSortDirection.Ascending)); this._termsView = termsView; this._termsViewContext = new DispatcherSynchronizationContext(termsView.Dispatcher); // Create commands. this._addTerm = new RelayCommand( _ => this.AddTermExecuted(), _ => !this.IsBusy && !this.IsEditMode); this._editTerm = new RelayCommand( p => this.EditTermExecuted(p), p => !this.IsBusy && !this.IsEditMode && this._terms.Contains(p)); this._deleteTerm = new RelayCommand( _ => this.DeleteTermExecuted(), p => !this.IsBusy && this._editingTerm != null); this._accept = new RelayCommand( _ => this.AcceptExecuted(), _ => !this.IsBusy && this.IsEditMode); this._cancel = new RelayCommand( _ => this.CancelExecuted(), _ => !this.IsBusy && this.IsEditMode); this._recreateStorage = new RelayCommand( _ => this.RecreateStorageExecuted(), _ => this._isInvalidStorage); this.StartLoadTerms(); }
/// <summary> /// Asserts <see cref="IDataErrorInfo"/> properties of the specified <see cref="TermEditViewModel"/>. /// </summary> /// <param name="model"><see cref="IDataErrorInfo"/> to assert.</param> /// <param name="isError">Indicates that <see cref="IDataErrorInfo"/> properties shouldn't be blank.</param> private static void AssertDataErrorInfo(IDataErrorInfo model, bool isError) { var nameProperty = PropertyExpressionHelper.GetName <ITermEditViewModel, string>(_ => _.Name); Assert.IsNotNull(model.Error); Assert.IsNotNull(model[nameProperty]); if (isError) { Assert.AreNotEqual(String.Empty, model.Error); Assert.AreNotEqual(String.Empty, model[nameProperty]); } else { Assert.AreEqual(String.Empty, model.Error); Assert.AreEqual(String.Empty, model[nameProperty]); } }
public static FilterBuilder CreateFor <TModel>(Expression <Func <TModel, object> > property) { return(new FilterBuilder(PropertyExpressionHelper.GetPropertyName(property))); }