Created
June 1, 2012 05:45
-
-
Save lukencode/2849237 to your computer and use it in GitHub Desktop.
thinkin fillr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NameFiller : IPropertyFiller<string> | |
{ | |
private Random _rand; | |
private static Regex _combinedRegex = new Regex("name|fullname|firstname|lastname|surname|middlename|maidenname", RegexOptions.IgnoreCase); | |
private static Regex _fullNameRegex = new Regex("name|fullname", RegexOptions.IgnoreCase); | |
private static Regex _firstNameRegex = new Regex("firstname|middlename", RegexOptions.IgnoreCase); | |
private static Regex _surnameRegex = new Regex("lastname|surname|maidenname", RegexOptions.IgnoreCase); | |
private static List<string> _firstNames = new List<string> { "Luke", "John", "Mary" }; | |
private static List<string> _surnames = new List<string> { "Lowrey", "Smith", "Peters" }; | |
public NameFiller() | |
{ | |
_rand = new Random(); | |
} | |
public bool ShouldFill(string propertyName, Type propertyType) | |
{ | |
if (propertyType != typeof(string)) | |
return false; | |
var cleaned = propertyName.Replace("_", ""); | |
return _combinedRegex.IsMatch(cleaned); | |
} | |
public string Fill(string propertyName, Type propertyType) | |
{ | |
var cleaned = propertyName.Replace("_", ""); | |
if (_firstNameRegex.IsMatch(cleaned)) | |
{ | |
return _firstNames.PickRandom(); | |
} | |
else if (_surnameRegex.IsMatch(cleaned)) | |
{ | |
return _surnames.PickRandom(); | |
} | |
else | |
{ | |
return _firstNames.PickRandom() + " " + _surnames.PickRandom(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not just use the PropertyInfo class instead of name and type?