Last active
July 17, 2017 06:21
-
-
Save bradleykronson/4d97f8c1ca02d774fdb1c95ce1d54160 to your computer and use it in GitHub Desktop.
Get Macro Parameter
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 TType GetMacroParam<TType>(PartialViewMacroModel model, string key, Func<string, TType> convert, TType fallback) | |
{ | |
if(!model.MacroParameters.ContainsKey(key)) | |
{ | |
return fallback; | |
} | |
var value = model.MacroParameters[key]; | |
if(value == null || value.ToString().Trim() == "") | |
{ | |
return fallback; | |
} | |
try | |
{ | |
return convert(value.ToString()); | |
} | |
catch (Exception) | |
{ | |
return fallback; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment