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


C# StringTemplate类代码示例

本文整理汇总了C#中StringTemplate的典型用法代码示例。如果您正苦于以下问题:C# StringTemplate类的具体用法?C# StringTemplate怎么用?C# StringTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Basic

        static void Basic()
        {
            StringTemplate stringTemplate = new StringTemplate("hello <data>");
            stringTemplate.Add("data", "world");

            Console.WriteLine(stringTemplate.Render());
        }
开发者ID:AdrianToman1,项目名称:StringTemplateEngine,代码行数:7,代码来源:Program.cs

示例2: Apply

 //= null
 public static string Apply(string template, Dictionary<string, object> @params )
 {
     StringTemplate st = new StringTemplate(template);
     AddDefaultAttributes(st);
     if (@params != null) AddAttributes(st, @params);
     return st.ToString();
 }
开发者ID:moscrif,项目名称:ide,代码行数:8,代码来源:FileTemplateUtilities.cs

示例3: StringTemplateView

        public StringTemplateView(StringTemplate template)
        {
            //null check
            if (template == null) throw new ArgumentNullException("template");

            //set template
            _template = template;
        }
开发者ID:shayfriedman,项目名称:AspNetMvcViewEnginesSamples,代码行数:8,代码来源:StringTemplateView.cs

示例4: TestStringTemplate

 static void TestStringTemplate()
 {
     string text = "$entity.Account$您好!<br/> 请点击连接重置您的秘密<br><a href=\"$url$\">$url$</a>";
     StringTemplate st = new StringTemplate(text);
     st.SetAttribute("entity", new Demo() { Account = "fengpengbin" });
     st.SetAttribute("url", "http://www.aporeboy.com/vail");
     Console.WriteLine(st.ToString());
 }
开发者ID:fengpb,项目名称:CodeNote,代码行数:8,代码来源:Program.cs

示例5: Populate

        public string Populate(ParameterSet parameterSet)
        {
            var t = new StringTemplate()
            {
                Text = Text,
            };

            return t.Populate(parameterSet.Parameters);
        }
开发者ID:John-Leitch,项目名称:GenomeDotNet,代码行数:9,代码来源:BatchScriptTemplate.cs

示例6: Export

        public string Export(IList dbObjects, string templatePath)
        {
            StringTemplate template = new StringTemplate();

            var text = File.ReadAllText(templatePath);

            //remove all tabs - it used only to format template code, not output code
            template.Template = text.Replace("\t", "");

            template.SetAttribute("dbObjects", dbObjects);
            var output = template.ToString();

            return output;
        }
开发者ID:vansickle,项目名称:dbexplorer,代码行数:14,代码来源:AbstractTextExporter.cs

示例7: Template

        public Template(string name)
        {
            var assembly = Assembly.GetCallingAssembly();
            var stream = assembly.GetManifestResourceStream(name);

            if (stream == null)
            {
                var candidates = string.Join(", ", assembly.GetManifestResourceNames());
                throw new FileNotFoundException(string.Format("cannot find embedded resource {0} in assembly {1}, candidate templates include [{2}]", name, assembly.GetName(), candidates));
            }

            var contents = new StreamReader(stream).ReadToEnd();
            template = new StringTemplate(contents);
        }
开发者ID:camswords,项目名称:custom-soap-webservice,代码行数:14,代码来源:Template.cs

示例8: Generate

        public static string Generate(string input, Dictionary<string, object> data)
        {
            var template = new StringTemplate(input);

            foreach (var d in data)
                template.SetAttribute(d.Key, d.Value);

            string result = template.ToString();
            ;
            template.Reset();
            data.Clear();
            template = null;
            return result;
        }
开发者ID:Kayomani,项目名称:FAP,代码行数:14,代码来源:TemplateEngine.cs

示例9: ListIterator_MultipleItems

        public void ListIterator_MultipleItems()
        {
            // Arrange
            var template = new StringTemplate("$user:{ u | <p>$u.FirstName$ is a super user? $u.IsSuperUser$. But his last name is $u.LastName$.</p>}$");
            var user = new { FirstName = "Ian", LastName = "Robinson", IsSuperUser = false };
            var userList = (new[] {user}).ToList();
            userList.Add(new { FirstName = "Gertrude", LastName = "Schmuckbucket", IsSuperUser = true});

            template.SetAttribute("user", userList);

            // Act
            var renderedText = template.ToString();

            // Assert
            Assert.AreEqual(renderedText, "<p>Ian is a super user? False. But his last name is Robinson.</p><p>Gertrude is a super user? True. But his last name is Schmuckbucket.</p>");
        }
开发者ID:irobinson,项目名称:BeerCollectionMVP,代码行数:16,代码来源:StringTemplateUsageExamples.cs

示例10: ListIterator_SingleItem

        public void ListIterator_SingleItem()
        {
            // Arrange
            var template = new StringTemplate("$user:{ u | $u.FirstName$ is a super user? $u.IsSuperUser$. But his last name is $u.LastName$.}$");
            template.SetAttribute("user", new
                                              {
                                                  FirstName = "Ian",
                                                  LastName = "Robinson",
                                                  IsSuperUser = false
                                              });
            // Act
            var renderedText = template.ToString();

            // Assert
            Assert.AreEqual(renderedText, "Ian is a super user? False. But his last name is Robinson.");
        }
开发者ID:irobinson,项目名称:BeerCollectionMVP,代码行数:16,代码来源:StringTemplateUsageExamples.cs

示例11: GetParserCreationTemplate

        public override StringTemplate GetParserCreationTemplate()
        {
            StringTemplate createParserST =
                new StringTemplate(
                    "        Profiler2 profiler = new Profiler2();\n" +
                    "        $parserName$ parser = new $parserName$(tokens,profiler);\n" +
                    "        profiler.setParser(parser);\n"
                    );

            if ( !Debug )
            {
                createParserST =
                    new StringTemplate(
                        "        $parserName$ parser = new $parserName$(tokens);\n"
                        );
            }

            return createParserST;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:19,代码来源:JavaRuntimeTestHarness.cs

示例12: NestedProperties

        public void NestedProperties()
        {
            // Arrange
            IDictionary<string, object> ret = new Dictionary<string, object>();
            ret["elem1"] = true;
            ret["elem2"] = false;

            var nestedObj = new Dictionary<string, object>();
            nestedObj["nestedProp"] = 100;
            ret["elem3"] = nestedObj;

            var template = new StringTemplate("$elem1$ or $elem2$ and value: $elem3.nestedProp$") { Attributes = ret };

            // Act
            var renderedText = template.ToString();

            // Assert
            Assert.AreEqual(renderedText, "True or False and value: 100");
        }
开发者ID:irobinson,项目名称:BeerCollectionMVP,代码行数:19,代码来源:StringTemplateUsageExamples.cs

示例13: AddAttributes

 public static void AddAttributes(StringTemplate st, Dictionary<string, object> @params)
 {
     foreach(string key in @params.Keys) {
         object val = @params[key];
         if (val != null) {
             if (val is string && String.IsNullOrEmpty(val as string))
                 continue;
             /*
            if (val is ArrayList)
             {
                 //st.SetAttribute(key, (val as ArrayList).ToArray());
                 ArrayList al = val as ArrayList;
                 foreach (object o in al)
                     st.SetAttribute(key, o);
             }
             else
             */
                 st.SetAttribute(key, val);
         }
     }
 }
开发者ID:moscrif,项目名称:ide,代码行数:21,代码来源:FileTemplateUtilities.cs

示例14: GetLexerTestFileTemplate

        public override StringTemplate GetLexerTestFileTemplate()
        {
            StringTemplate outputFileST = new StringTemplate(
                "import org.antlr.runtime.*;\n" +
                "import org.antlr.runtime.tree.*;\n" +
                "import org.antlr.runtime.debug.*;\n" +
                "\n" +
                "class Profiler2 extends Profiler {\n" +
                "    public void terminate() { ; }\n" +
                "}\n" +
                "public class Test {\n" +
                "    public static void main(String[] args) throws Exception {\n" +
                "        CharStream input = new ANTLRFileStream(args[0]);\n" +
                "        $lexerName$ lex = new $lexerName$(input);\n" +
                "        CommonTokenStream tokens = new CommonTokenStream(lex);\n" +
                "        System.out.println(tokens);\n" +
                "    }\n" +
                "}"
                );

            return outputFileST;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:22,代码来源:JavaRuntimeTestHarness.cs

示例15: StringTemplatAddDuplicateSameValuesTest

        public void StringTemplatAddDuplicateSameValuesTest()
        {
            target = new StringTemplate(String.Empty);

            target.Add("test", "one");

            try
            {
                target.Add("test", "one");

                Assert.Fail("No exception thrown");
            }
            catch (ArgumentException exception)
            {
                Assert.AreEqual("Element has already been added.\r\nParameter name: element", exception.Message);
                Assert.AreEqual("element", exception.ParamName);
            }
            catch
            {
                Assert.Fail("ArgumentException not thrown");
            }
        }
开发者ID:AdrianToman1,项目名称:StringTemplateEngine,代码行数:22,代码来源:StringTemplateUnitTests.cs


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