Skip to content

Commit

Permalink
Gracefully handle invalid value enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
programcsharp committed May 14, 2015
1 parent 28ea57b commit 3bf131e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Build/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.5")]
[assembly: AssemblyFileVersion("1.1.5")]
[assembly: AssemblyVersion("1.1.6")]
[assembly: AssemblyFileVersion("1.1.6")]
2 changes: 2 additions & 0 deletions Griddly.Mvc/GriddlyColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public virtual HtmlString RenderValue(object value, bool encode = true)
else
value = value.ToString();

if (value == null)
return null;
if (value is HtmlString)
return (HtmlString)value;
else if (encode)
Expand Down
4 changes: 3 additions & 1 deletion Griddly.Mvc/InternalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ internal static HtmlString GetHtmlView(string value, bool turnUrlsIntoLinks = fa

internal static string ToStringDescription(Enum value)
{
if (value == null || !Enum.IsDefined(value.GetType(), value))
if (value == null)
return null;
else if (!Enum.IsDefined(value.GetType(), value))
return "[Undefined " + value.GetType().Name + " Value: " + value + "]";

return GetEnumDescription(value.GetType().GetField(value.ToString()));
}
Expand Down

0 comments on commit 3bf131e

Please sign in to comment.