Skip to content

Instantly share code, notes, and snippets.

@JoeStead
Created March 8, 2016 15:13
Show Gist options
  • Save JoeStead/90da76bbacac331e3a86 to your computer and use it in GitHub Desktop.
Save JoeStead/90da76bbacac331e3a86 to your computer and use it in GitHub Desktop.
Generates some docs stuff for fluent validation
public void Stuff()
{
var what = AllRules();
foreach (var s in what)
{
Debug.WriteLine(s);
}
}
public List<string> AllRules()
{
var descriptor = this.CreateDescriptor();
return (from member in descriptor.GetMembersWithValidators()
from validationRule in descriptor.GetRulesForMember(member.Key)
select (PropertyRule) validationRule
into rule
from validator in rule.Validators
select $"validation type:{validator.ToString().Replace("FluentValidation.Validators.", "")} " +
$"| property:{rule.PropertyName} " +
$"| type:{rule.Member.ToString().Split(' ').FirstOrDefault()} " +
$"| Regex:{(validator as RegularExpressionValidator)?.Expression}").ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment