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); }
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); } } }