Created
May 7, 2020 20:56
-
-
Save enisn/4dcab8503e2e2bb51982ee216803d164 to your computer and use it in GitHub Desktop.
Challenge #2 - Solution - BindObjectProperties
This file contains hidden or 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 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