/// <summary> /// Marks the value as required. /// </summary> /// <param name="errorMessage">The error message.</param> /// <param name="errorMessageResourceType">Type of the error message resource.</param> /// <param name="errorMessageResourceName">Name of the error message resource.</param> /// <returns></returns> protected virtual TItemBuilder Required(Func <string> errorMessage, Type errorMessageResourceType, string errorMessageResourceName) { Item.IsRequired = true; RequiredValidationMetadata requiredValidation = Item.GetValidationOrCreateNew <RequiredValidationMetadata>(); requiredValidation.ErrorMessage = errorMessage; requiredValidation.ErrorMessageResourceType = errorMessageResourceType; requiredValidation.ErrorMessageResourceName = errorMessageResourceName; return(This); }
/// <summary> /// Marks the value as optional, this is handy when the framework initializes the /// value as required and you want to negate it. /// </summary> /// <returns></returns> public TItemBuilder Optional() { Item.IsRequired = false; RequiredValidationMetadata requiredValidation = Item.GetValidation <RequiredValidationMetadata>(); if (requiredValidation != null) { Item.Validations.Remove(requiredValidation); } return(This); }