Skip to content

Commit

Permalink
Add truthy check for numerics (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
emazv72 authored and Romanx committed May 18, 2019
1 parent efc6b3d commit 8654bf0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Stubble.Core/Contexts/Context.cs
Expand Up @@ -195,6 +195,32 @@ public bool IsTruthyValue(object value)
return (bool)value;
}

if (value is int)
{
return (int)value != 0;
}

if (value is long)
{
return (long)value != 0;
}

if (value is decimal)
{
return (decimal)value != 0m;
}

if (value is float)
{
return (float)value != 0f;
}


if (value is double)
{
return (double)value != 0d;
}

if (value is string strValue)
{
var trimmed = strValue.Trim();
Expand Down

0 comments on commit 8654bf0

Please sign in to comment.