protected override void OnParametersSet()
        {
            if (Min is not null && !typeof(IComparable <TValue>).IsAssignableFrom(Min.GetType()))
            {
                throw new InvalidOperationException($"{nameof(RateInputMinMaxNumberAbstractBase<TValue>)} requires a {nameof(Min)} " +
                                                    $"parameter to implement {nameof(IComparable<TValue>)} and it is of type {typeof(TValue)}.");
            }

            if (Max is not null && !typeof(IComparable <TValue>).IsAssignableFrom(Max.GetType()))
            {
                throw new InvalidOperationException($"{nameof(RateInputMinMaxNumberAbstractBase<TValue>)} requires a {nameof(Max)} " +
                                                    $"parameter to implement {nameof(IComparable<TValue>)} and it is of type {typeof(TValue)}.");
            }

            if (Min is not null && Max is not null && (Min as IComparable <TValue>) !.CompareTo(Max) > 0)
            {
                throw new InvalidOperationException($"{nameof(RateInputMinMaxNumberAbstractBase<TValue>)} requires a {nameof(Min)} " +
                                                    $"parameter to be less or equal than {nameof(Max)} parameter.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 値が日時の場合の範囲指定パラメータのチェックとHTMLへの反映
        /// </summary>
        /// <param name="context"></param>
        private void CheckDatetimeParameter(ClientModelValidationContext context)
        {
            // Minのチェックと設定
            if (Min != null)
            {
                // Minは時間以外はエラー
                if (getNumberType(Min.GetType()) != RangeValueTypes.String)
                {
                    throw new VueServerException("範囲指定のバリデーションで日時の項目に日時以外の「Min」が設定されています。");
                }
                DateTime work;
                if (!DateTime.TryParse(Min.ToString(), out work))
                {
                    throw new VueServerException("範囲指定のバリデーションで日時の項目に日時以外の「Min」が設定されています。");
                }

                // タグの属性[min]に最小値を設定
                context.Attributes["min"] = Min.ToString();

                // 最小値の異常メッセージが設定されている場合はタグの属性[min-error-message]に設定
                if (!string.IsNullOrEmpty(MinErrorMessage))
                {
                    context.Attributes["min-error-message"] = MinErrorMessage;
                }
            }

            // 最大値と最大値のエラーメッセージを設定
            if (Max != null)
            {
                // Minは時間以外はエラー
                if (getNumberType(Max.GetType()) != RangeValueTypes.String)
                {
                    throw new VueServerException("範囲指定のバリデーションで日時の項目に日時以外の「Max」が設定されています。");
                }
                DateTime work;
                if (!DateTime.TryParse(Max.ToString(), out work))
                {
                    throw new VueServerException("範囲指定のバリデーションで日時の項目に日時以外の「Max」が設定されています。");
                }

                // タグの属性[max]に最小値を設定
                context.Attributes["max"] = Max.ToString();

                // 最大値の異常メッセージが設定されている場合はタグの属性[max-error-message]に設定
                if (!string.IsNullOrEmpty(MaxErrorMessage))
                {
                    context.Attributes["max-error-message"] = MaxErrorMessage;
                }
            }

            // StepとStepのエラーメッセージを設定
            if (Step != null)
            {
                // Stepは時間以外はエラー
                if (getNumberType(Step.GetType()) != RangeValueTypes.String)
                {
                    throw new VueServerException("範囲指定のバリデーションで日時の項目に日時以外の「Step」が設定されています。");
                }
                DateTime work;
                if (!DateTime.TryParse(Step.ToString(), out work))
                {
                    throw new VueServerException("範囲指定のバリデーションで日時の項目に日時以外の「Step」が設定されています。");
                }

                // タグの属性[step]に最小値を設定
                context.Attributes["step"] = Step.ToString();

                // 最刻み幅の異常メッセージが設定されている場合はタグの属性[step-error-message]に設定
                if (!string.IsNullOrEmpty(StepErrorMessage))
                {
                    context.Attributes["step-error-message"] = StepErrorMessage;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 値が実数の場合の範囲指定パラメータのチェックとHTMLへの反映
        /// </summary>
        /// <param name="context"></param>
        private void CheckRealParamtere(ClientModelValidationContext context)
        {
            // Minのチェックと設定
            if (Min != null)
            {
                var minType = getNumberType(Min.GetType());

                // Minは整数と小数以外はエラー
                if (minType != RangeValueTypes.Integer && minType != RangeValueTypes.Real)
                {
                    throw new VueServerException("範囲指定のバリデーションで実数の項目に数値以外の「Min」が設定されています。");
                }

                // タグの属性[min]に最小値を設定
                context.Attributes["min"] = Min.ToString();

                // 最小値の異常メッセージが設定されている場合はタグの属性[min-error-message]に設定
                if (!string.IsNullOrEmpty(MinErrorMessage))
                {
                    context.Attributes["min-error-message"] = MinErrorMessage;
                }
            }

            // 最大値と最大値のエラーメッセージを設定
            if (Max != null)
            {
                var maxType = getNumberType(Max.GetType());

                // Minは整数以外はエラー
                if (maxType != RangeValueTypes.Integer && maxType != RangeValueTypes.Real)
                {
                    throw new VueServerException("範囲指定のバリデーションで実数の項目に数値以外の「Max」が設定されています。");
                }

                // タグの属性[max]に最小値を設定
                context.Attributes["max"] = Max.ToString();

                // 最大値の異常メッセージが設定されている場合はタグの属性[max-error-message]に設定
                if (!string.IsNullOrEmpty(MaxErrorMessage))
                {
                    context.Attributes["max-error-message"] = MaxErrorMessage;
                }
            }

            // StepとStepのエラーメッセージを設定
            if (Step != null)
            {
                var stepType = getNumberType(Step.GetType());

                // Stepは整数以外はエラー
                if (stepType != RangeValueTypes.Integer && stepType != RangeValueTypes.Real)
                {
                    throw new VueServerException("範囲指定のバリデーションで整数の項目に整数以外の「Step」が設定されています。");
                }

                // タグの属性[step]に最小値を設定
                context.Attributes["step"] = Step.ToString();

                // 最刻み幅の異常メッセージが設定されている場合はタグの属性[step-error-message]に設定
                if (!string.IsNullOrEmpty(StepErrorMessage))
                {
                    context.Attributes["step-error-message"] = StepErrorMessage;
                }
            }
        }