NVelocity是否不再支持字符串模板?

Kyl*_*est 5 nvelocity

我们在嵌入式资源中有一堆用于电子邮件的NVelocity模板.我们希望将这些模板移动到数据库,以便用户可以轻松配置它们.

虽然NVelocity(Castle端口)似乎不支持字符串作为模板.有谁知道怎么做.

要清楚这是我想要做的(语法可能不准确,我要记忆)...

string templateString = "Hello $!user";
Template template = new Template(templateString);
string results = template.Merge(....);
Run Code Online (Sandbox Code Playgroud)

Ber*_*ius 15

这对我有用:

using System.Collections;
using System.IO;
using NUnit.Framework;
using NVelocity;
using NVelocity.App;

[Test]
public void StringParsing()
{
    var h = new Hashtable {
        { "foo", "Template" },
        { "bar", "is working" },
        { "foobar", new[] { "1", "2", "3" } } };
    Velocity.Init();
    var c = new VelocityContext( h );
    var s = new StringWriter();
    Velocity.Evaluate( c, s, "",
        "$foo $bar: #foreach ($i in $foobar)$i#end" );
    Assert.AreEqual( "Template is working: 123", s.ToString() );
}
Run Code Online (Sandbox Code Playgroud)