コード例 #1
0
        public static TContentSchema AddString <TContentSchema>(this TContentSchema schema, string name, Action <StringFieldOptions>?configOptions = null)
            where TContentSchema : IContentSchema
        {
            StringFieldOptions options = new StringFieldOptions();

            configOptions?.Invoke(options);

            schema.AddField <StringField>(name, options, null);

            return(schema);
        }
コード例 #2
0
ファイル: StringField.cs プロジェクト: usercode/DragonFly
        public override void Validate(string fieldName, ContentFieldOptions options, ValidationContext context)
        {
            StringFieldOptions fieldOptions = (StringFieldOptions)options;

            if (fieldOptions.IsRequired && HasValue == false)
            {
                context.AddRequireValidation(fieldName);
            }

            if (HasValue)
            {
                if (Value.Length < fieldOptions.MinLength)
                {
                    context.AddMinimumValidation(fieldName, fieldOptions.MinLength);
                }
                else if (Value.Length > fieldOptions.MaxLength)
                {
                    context.AddMaximumValidation(fieldName, fieldOptions.MaxLength);
                }
            }
        }