Skip to content

Instantly share code, notes, and snippets.

@enisn
Created May 7, 2020 20:56
Show Gist options
  • Save enisn/4dcab8503e2e2bb51982ee216803d164 to your computer and use it in GitHub Desktop.
Save enisn/4dcab8503e2e2bb51982ee216803d164 to your computer and use it in GitHub Desktop.
Challenge #2 - Solution - BindObjectProperties
public static string BindObjectProperties(this string source, object obj)
{
if(obj == default) return source;
var type = obj.GetType();
foreach(var parameter in ExtractParams(source))
{
source = source.Replace("{"+ parameter +"}", type.GetProperty(parameter)?.GetValue(obj)?.ToString());
}
return source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment