本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroupFile.RegisterModelAdaptor方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroupFile.RegisterModelAdaptor方法的具体用法?C# TemplateGroupFile.RegisterModelAdaptor怎么用?C# TemplateGroupFile.RegisterModelAdaptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr4.StringTemplate.TemplateGroupFile
的用法示例。
在下文中一共展示了TemplateGroupFile.RegisterModelAdaptor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSimpleAdaptor
public void TestSimpleAdaptor()
{
string templates =
"foo(x) ::= \"<x.id>: <x.name>\"\n";
writeFile(tmpdir, "foo.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "foo.stg"));
group.RegisterModelAdaptor(typeof(User), new UserAdaptor());
Template st = group.GetInstanceOf("foo");
st.Add("x", new User(100, "parrt"));
string expecting = "100: parrt";
string result = st.Render();
Assert.AreEqual(expecting, result);
}
示例2: TestWeCanResetAdaptorCacheInvalidatedUponAdaptorReset
public void TestWeCanResetAdaptorCacheInvalidatedUponAdaptorReset()
{
string templates =
"foo(x) ::= \"<x.id>: <x.name>\"\n";
writeFile(tmpdir, "foo.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "foo.stg"));
group.RegisterModelAdaptor(typeof(User), new UserAdaptor());
group.GetModelAdaptor(typeof(User)); // get User, SuperUser into cache
group.GetModelAdaptor(typeof(SuperUser));
group.RegisterModelAdaptor(typeof(User), new UserAdaptorConst());
// cache should be reset so we see new adaptor
Template st = group.GetInstanceOf("foo");
st.Add("x", new User(100, "parrt"));
string expecting = "const id value: const name value"; // sees UserAdaptorConst
string result = st.Render();
Assert.AreEqual(expecting, result);
}
示例3: TestSeesMostSpecificAdaptor
public void TestSeesMostSpecificAdaptor()
{
string templates =
"foo(x) ::= \"<x.id>: <x.name>\"\n";
writeFile(tmpdir, "foo.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "foo.stg"));
group.RegisterModelAdaptor(typeof(User), new UserAdaptor());
group.RegisterModelAdaptor(typeof(SuperUser), new UserAdaptorConst()); // most specific
Template st = group.GetInstanceOf("foo");
st.Add("x", new User(100, "parrt"));
string expecting = "100: parrt";
string result = st.Render();
Assert.AreEqual(expecting, result);
st.Remove("x");
st.Add("x", new SuperUser(100, "parrt"));
expecting = "const id value: const name value"; // sees UserAdaptorConst
result = st.Render();
Assert.AreEqual(expecting, result);
}
示例4: TestAdaptorAndBadProp
public void TestAdaptorAndBadProp()
{
ErrorBufferAllErrors errors = new ErrorBufferAllErrors();
string templates =
"foo(x) ::= \"<x.qqq>\"\n";
writeFile(tmpdir, "foo.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "foo.stg"));
group.Listener = errors;
group.RegisterModelAdaptor(typeof(User), new UserAdaptor());
Template st = group.GetInstanceOf("foo");
st.Add("x", new User(100, "parrt"));
string expecting = "";
string result = st.Render();
Assert.AreEqual(expecting, result);
TemplateRuntimeMessage msg = (TemplateRuntimeMessage)errors.Errors[0];
TemplateNoSuchPropertyException e = (TemplateNoSuchPropertyException)msg.Cause;
Assert.AreEqual("User.qqq", e.PropertyName);
}