jeudi 16 février 2017

How can I extract the regular expression from a RegularExpressionAttribute?

I have a class like

public class Foo
{
    [RegularExpression(@"([A-Za-z0-9\-_ ]+){1,100}")]
    public string Bar { get; set; }
}

and for the purpose of unit testing I want to be able to extract out the "@"([A-Za-z0-9\-_ ]+){1,100}".

I know it's something like

string expr = typeof(Foo).GetProperty("Bar").....

but I don't quite know how to finish it.





Aucun commentaire:

Enregistrer un commentaire