Skip to content

Support valdation attributes on types #75

@Corniel

Description

@Corniel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions