/// <summary>
        /// Includes server validation metadata to a reactive property.
        /// When this is included, the property value will be sent to the server when it changed.
        /// </summary>
        /// <param name="prop">Property to include.</param>
        /// <param name="vm">View model of the property.</param>
        /// <param name="validate">Validation function.</param>
        /// <param name="message">Validation message.</param>
        /// <param name="category">Validation category.</param>
        /// <returns>Property.</returns>
        public static ReactiveProperty <TProp> WithServerValidation <TProp>(this ReactiveProperty <TProp> prop,
                                                                            IReactiveProperties vm, Func <TProp, bool> validate, string message, Validation.Categories category = Validation.Categories.Error)
        {
            var serverValidation  = new ServerValidation(message);
            var validationMsgProp = typeof(BaseVM).IsAssignableFrom(vm.GetType()) ?
                                    (vm as BaseVM).AddProperty <bool>(ToValidationMessageName(prop, serverValidation.Id))
            : vm.AddProperty <bool>(ToValidationMessageName(prop, serverValidation.Id));

            validationMsgProp.SubscribeTo(prop.Select(val => validate(val)));
            return(prop.WithValidation(vm, serverValidation));
        }
Beispiel #2
0
        /// <summary>
        /// Includes server validation metadata to a reactive property.
        /// When this is included, the property value will be sent to the server when it changed.
        /// </summary>
        /// <param name="prop">Property to include.</param>
        /// <param name="vm">View model of the property.</param>
        /// <param name="validate">Validation function.</param>
        /// <param name="message">Validation message.</param>
        /// <param name="category">Validation category.</param>
        /// <returns>Property.</returns>
        public static ReactiveProperty <TProp> WithServerValidation <TProp>(this ReactiveProperty <TProp> prop,
                                                                            Func <TProp, bool> validate, string message, Validation.Categories category = Validation.Categories.Error)
        {
            var vm = prop.ViewModel ?? throw new NullReferenceException($"Property '{prop.Name}' has no view model!");
            var serverValidation  = new ServerValidation(message);
            var validationMsgProp = typeof(BaseVM).IsAssignableFrom(vm.GetType()) ?
                                    (vm as BaseVM).AddProperty <bool>(ToValidationMessageName(prop, serverValidation.Id))
            : vm.AddProperty <bool>(ToValidationMessageName(prop, serverValidation.Id));

            validationMsgProp.SubscribeTo(prop.Select(val => validate(val)));
            return(prop.WithValidation(serverValidation));
        }