From 5b9281fc2f0829527db15492d86192fe5f360e31 Mon Sep 17 00:00:00 2001 From: unarist Date: Wed, 6 Apr 2016 00:22:49 +0900 Subject: [PATCH] Fixed ArgumentException on compiling when the model has ToString() method --- Nustache.Compilation.Tests/Compiled_Templates_Support.cs | 4 ++-- Nustache.Compilation/CompilePartVisitor.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Nustache.Compilation.Tests/Compiled_Templates_Support.cs b/Nustache.Compilation.Tests/Compiled_Templates_Support.cs index 6594341..5059121 100644 --- a/Nustache.Compilation.Tests/Compiled_Templates_Support.cs +++ b/Nustache.Compilation.Tests/Compiled_Templates_Support.cs @@ -29,7 +29,7 @@ public class SubObject public override string ToString() { return "SubObject"; - } + } } public class TestObjectWithToString @@ -304,7 +304,7 @@ public void Model_With_ToString() var result = compiled(new TestObjectWithToString { TestString = "Hello"}); Assert.AreEqual("A template with Hello", result); } - + private Func Compiled(string text) where T : class { return Template(text).Compile(null); diff --git a/Nustache.Compilation/CompilePartVisitor.cs b/Nustache.Compilation/CompilePartVisitor.cs index 88ce161..f6e59e0 100644 --- a/Nustache.Compilation/CompilePartVisitor.cs +++ b/Nustache.Compilation/CompilePartVisitor.cs @@ -115,7 +115,7 @@ public void Visit(VariableReference variable) { var getter = context.CompiledGetter(variable.Path); var returnIfNotNull = Expression.Call(getter, getter.Type.GetMethod("ToString", new Type[0])); - getter = CompoundExpression.NullCheck(getter, "", returnIfNotNull); + getter = CompoundExpression.NullCheck(getter, "", returnIfNotNull); if (variable.Escaped) {