Skip to content

Commit

Permalink
Refactored the GetValue method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstebo committed Feb 19, 2019
1 parent 0090a1f commit 22ec9e7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/FakerDotNet/Fakers/FakeFaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ private PropertyInfo GetFaker(string name)

private string GetValue(PropertyInfo propertyInfo, string methodName)
{
var method = propertyInfo.PropertyType
.GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

if (method == null) throw new FormatException($"Invalid method: {propertyInfo.Name}.{methodName}");

const BindingFlags flags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance;
var method = propertyInfo.PropertyType.GetMethod(methodName, flags)
?? throw new FormatException($"Invalid method: {propertyInfo.Name}.{methodName}");

var parameters = method.GetParameters().Select(DefaultValue).ToArray();
var value = method.Invoke(propertyInfo.GetValue(_fakerContainer, null), parameters);

return Convert.ToString(method.Invoke(propertyInfo.GetValue(_fakerContainer, null), parameters));
return Convert.ToString(value);
}

private static object DefaultValue(ParameterInfo parameterInfo)
Expand Down

0 comments on commit 22ec9e7

Please sign in to comment.