您可以将注入属性值与注入数据模型混合使用吗

时间:2019-07-02 07:48:13

标签: antlr4 stringtemplate

我在c#类中定义了一个数据模型。我希望将其注入到StringTemplate模板中。我也希望将属性注入相同的模板中。但是我似乎无法同时做这两项。

我尝试了使用聚集注入和类注入的简单模板-它们似乎可以分开工作但不能一起工作。

//声明

var strTemplate = "<Entry.a> <Entry.b> <Entry.x> <Entry.y> <Entry.z>";
var test1 = new StringTemplate(strTemplate);
var test2 = new StringTemplate(strTemplate);
var test3 = new StringTemplate(strTemplate);

//测试1-按预期工作

test1.AddMany("Entry.{a,b}", "Hello", "World");
string res1 =test1.Render();

//测试2-正常工作

var data = new { x=1,y=2,z=3};
test2.Add("Entry", data);
string res2 =test2.Render();

//测试3-不起作用-空白输出

test3.AddMany("Entry.{a,b}", "Hello", "World");
test3.Add("Entry", data);
string res3 =test3.Render();

//获得的结果

// test1 res1 =“ Hello World”;

// test2 res2 =“ 1 2 3”

// test3 res3 =“”

//预期结果

// test1 res1 =“ Hello World”;

// test2 res2 =“ 1 2 3”

// test3 res3 =“ Hello World 1 2 3”

0 个答案:

没有答案
相关问题