1

我想将几个模板文件放在一个名为“Templates”的目录中,相对于我的应用程序的可执行文件,并使用它们。例如,一个模板文件被命名为“Globals.st”。

这样,我创建了一个 TemplateGroupDirectory 并加载了模板:

var group = new TemplateGroupDirectory("Templates");
var tmpl = group.GetInstanceOf("Globals");

在尝试获取模板实例时,我收到一条消息说发生了 NullReferenceException。

我错过了什么?

4

1 回答 1

1

可能是语法问题

这是一个例子:

string fullpath = Path.GetFullPath("templates/");
TemplateGroupDirectory tgd = new TemplateGroupDirectory(fullpath ,'<','>');
Template t = tgd.GetInstanceOf("helloworld");
t.Add("world", "shitty world");

我有一个名为模板的文件夹,其中包含文件 helloworld.st

helloworld(world) ::= <<
hello, <world>
>>

我最好的猜测是,当您使用相对路径时,它找不到您需要的 .st 文件,记得在 .st 文件的属性上放置更新或始终 coby 的副本,否则模板将一无所有。

于 2015-06-09T12:44:32.187 回答