当前位置: 首页>>代码示例>>C#>>正文


C# TemplateGroupFile.RegisterModelAdaptor方法代码示例

本文整理汇总了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);
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:13,代码来源:TestModelAdaptors.cs

示例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);
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:18,代码来源:TestModelAdaptors.cs

示例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);
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:20,代码来源:TestModelAdaptors.cs

示例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);
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:19,代码来源:TestModelAdaptors.cs


注:本文中的Antlr4.StringTemplate.TemplateGroupFile.RegisterModelAdaptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。