nustache.core未评估布尔值

时间:2018-06-21 14:24:52

标签: .net-core nustache

RenderTemplate方法

public static string RenderTemplate(string json, string template)
{
    try
    {
        dynamic obj = JsonConvert.DeserializeObject(json);
        return Render.StringToString(template,obj);
    }
    catch (Exception e)
    {
        throw e;
    }
}

Json

[  
    {  
       "Item":"Some Item",
       "Unit":"10x10",
       "Quantity":3.0,
       "Amount":0.0,
       "ExpiryDate":"2018-09-07T00:00:00",
       "NumberOfDaysToExpiry":79,
       "lessThan14":false
   }
]

案例1 与模板

{{#.}}
    {{Item}}
{{/.}}

工作正常

案例2 与模板

{{#.}}
    {{#lessThan14}} {{Unit}}, {{Quantity}}, {{Amount}}, {{ExpiryDate}}, {{NumberOfDaysToExpiry}} {{/lessThan14}}
{{/.}}

工作正常

案例3 与模板

{{#.}}
    {{lessThan14}}
{{/.}}

打印出 False ,这是错误的,因为胡须布尔不评估任何字母是否为大写字母,仍然可以解决逻辑错误

案例4 与模板

{{#.}}
    {{#lessThan14}} {{Item}} {{/lessThan14}}
{{/.}}

在这种情况下,程序无法引发异常

System.Reflection.TargetParameterCountException: Parameter count mismatch.
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, 
       BindingFlags invokeAttr, Binder binder, Object[] parameters, 
       CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags 
       invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] 
       index)
   at Nustache.Core.RenderContext.GetValueFromPath(Object data, String path, 
       Boolean& partialMatch)
   at Nustache.Core.RenderContext.GetValue(String path)
   at Nustache.Core.VariableReference.Render(RenderContext context)
   at Nustache.Core.Section.RenderParts(RenderContext context)
   at Nustache.Core.Block.Render(RenderContext context)
   at Nustache.Core.Section.RenderParts(RenderContext context)
   at Nustache.Core.Block.Render(RenderContext context)
   at Nustache.Core.Section.RenderParts(RenderContext context)
   at Nustache.Core.Template.Render(Object data, TextWriter writer, 
       TemplateLocator templateLocator, RenderContextBehaviour 
       renderContextBehaviour)
   at Nustache.Core.Render.StringToString(String template, Object data, 
       TemplateLocator templateLocator, RenderContextBehaviour 
       renderContextBehaviour)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet] 
       (CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at TemplateRendering.Program.RenderTemplate(String json, String template) 
       in 
    C:\Users\source\repos\TemplateRendering\TemplateRendering\Program.cs:line 
    39 

我想念什么?因为这在 .net nustache 中起作用,但是对于 .net core

的失败

0 个答案:

没有答案