Skip to content

Support valdation attributes on types #75

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions