MiniValidation icon indicating copy to clipboard operation
MiniValidation copied to clipboard

Support valdation attributes on types

Open Corniel opened this issue 9 months ago • 1 comments

I've built a nested Data Annotations validator myself. It turns out that yours is faster (in most cases), so I'm considering dropping my own validator in favor of this one. However, I noticed that you do not support ValidationAttributes on types. Was that a deliberate choice, or is some ware on your to-do list?

[Fact]
public void Invalid_When_Model_Is_Invalid_By_TypeAttribute()
{
    var sot = new TestClass();
    var result = MiniValidator.TryValidate(sot, out var errors);
    Assert.False(result);
    Assert.Single(errors);
    Assert.Equal(string.Empty, errors.Keys.First());
}

[InvalidType]
class TestClass { }


[AttributeUsage(AttributeTargets.Class)]
class InvalidTypeAttribute : ValidationAttribute
{
    public override bool IsValid(object? value) => false;
}

Corniel avatar Mar 21 '25 09:03 Corniel

Is there any update on this? I'm facing the same issue.

JeevanJames avatar Aug 26 '25 16:08 JeevanJames