Skip to content

Instantly share code, notes, and snippets.

@bradleykronson
Last active July 17, 2017 06:21
Show Gist options
  • Save bradleykronson/4d97f8c1ca02d774fdb1c95ce1d54160 to your computer and use it in GitHub Desktop.
Save bradleykronson/4d97f8c1ca02d774fdb1c95ce1d54160 to your computer and use it in GitHub Desktop.
Get Macro Parameter
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