Added property validation

This commit is contained in:
2025-01-16 16:16:50 +01:00
parent c3c69466d4
commit d8596aa5e1
5 changed files with 101 additions and 24 deletions

View File

@@ -14,11 +14,12 @@ public class PropertyConfig(PropertyInfo info, TableConfig table) {
public Func<object, string>? Formatter { get; set; }
public Func<string, object>? Parser { get; set; }
public Func<object>? Template { get; set; }
public Func<object?, Task<IEnumerable<string>>>? Validator { get; set; }
public bool Editable { get; set; } = true;
public bool Creatable { get; set; } = true;
public bool DisplayValue { get; set; } = true;
public bool IsRelation { get; set; }
public bool IsPrimaryKey { get; set; }
public bool IsRequired { get; set; }
}
public class PropertyConfig<TProp>(PropertyConfig config) {
@@ -79,4 +80,14 @@ public class PropertyConfig<TProp>(PropertyConfig config) {
InnerConfig.DisplayValue = display;
return this;
}
public PropertyConfig<TProp> Validator(Func<TProp?, IEnumerable<string>> validator) {
InnerConfig.Validator = obj => Task.FromResult(validator.Invoke((TProp?)obj));
return this;
}
public PropertyConfig<TProp> Validator(Func<TProp?, Task<IEnumerable<string>>> validator) {
InnerConfig.Validator = obj => validator.Invoke((TProp?)obj);
return this;
}
}