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


C# ExtendedProperties.Add方法代码示例

本文整理汇总了C#中Commons.Collections.ExtendedProperties.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ExtendedProperties.Add方法的具体用法?C# ExtendedProperties.Add怎么用?C# ExtendedProperties.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Commons.Collections.ExtendedProperties的用法示例。


在下文中一共展示了ExtendedProperties.Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_Example1

        public void Test_Example1()
        {
            String templateFile = "example1.vm";
            try {
            /*
             * setup
             */

            Velocity.SetProperty(NVelocity.Runtime.RuntimeConstants_Fields.FILE_RESOURCE_LOADER_PATH, "../test/templates");
            Velocity.Init();

            /*
             *  Make a context object and populate with the data.  This
             *  is where the Velocity engine gets the data to resolve the
             *  references (ex. $list) in the template
             */
            VelocityContext context = new VelocityContext();
            context.Put("list", GetNames());

            ExtendedProperties props = new ExtendedProperties();
            props.Add("runtime.log", "nvelocity.log");
            context.Put("props", props);

            /*
             *    get the Template object.  This is the parsed version of your
             *  template input file.  Note that getTemplate() can throw
             *   ResourceNotFoundException : if it doesn't find the template
             *   ParseErrorException : if there is something wrong with the VTL
             *   Exception : if something else goes wrong (this is generally
             *        indicative of as serious problem...)
             */
            Template template =  null;

            try {
            template = Velocity.GetTemplate(templateFile)
            ;
            } catch( ResourceNotFoundException rnfe ) {
            Console.Out.WriteLine("Example : error : cannot find template " + templateFile + " : \n" + rnfe.Message);
            Assertion.Fail();
            } catch( ParseErrorException pee ) {
            Console.Out.WriteLine("Example : Syntax error in template " + templateFile + " : \n" + pee );
            Assertion.Fail();
            }

            /*
             *  Now have the template engine process your template using the
             *  data placed into the context.  Think of it as a  'merge'
             *  of the template and the data to produce the output stream.
             */

            // using Console.Out will send it to the screen
            TextWriter writer = new StringWriter();
            if ( template != null)
            template.Merge(context, writer);

            /*
             *  flush and cleanup
             */

            writer.Flush();
            writer.Close();
            } catch(System.Exception ex) {
            Console.Out.WriteLine(ex);
            Assertion.Fail();
            }
        }
开发者ID:DF-thangld,项目名称:web_game,代码行数:66,代码来源:ParserTest.cs


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