From 8654bf0d607dc68cdac0db3718cf6a715b0fd6b8 Mon Sep 17 00:00:00 2001 From: emazv72 Date: Sat, 18 May 2019 20:21:21 +0200 Subject: [PATCH] Add truthy check for numerics (#52) #53 --- src/Stubble.Core/Contexts/Context.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Stubble.Core/Contexts/Context.cs b/src/Stubble.Core/Contexts/Context.cs index bc5c83d..45ad630 100644 --- a/src/Stubble.Core/Contexts/Context.cs +++ b/src/Stubble.Core/Contexts/Context.cs @@ -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();