本文整理汇总了C#中StringTemplate.Add方法的典型用法代码示例。如果您正苦于以下问题:C# StringTemplate.Add方法的具体用法?C# StringTemplate.Add怎么用?C# StringTemplate.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringTemplate
的用法示例。
在下文中一共展示了StringTemplate.Add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Basic
static void Basic()
{
StringTemplate stringTemplate = new StringTemplate("hello <data>");
stringTemplate.Add("data", "world");
Console.WriteLine(stringTemplate.Render());
}
示例2: 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");
}
}
示例3: StringTemplateAddElementEmptyTest
public void StringTemplateAddElementEmptyTest()
{
target = new StringTemplate("test");
try
{
target.Add(String.Empty, new Object());
Assert.Fail("No exception thrown");
}
catch (ArgumentException exception)
{
Assert.AreEqual("element", exception.ParamName);
}
catch
{
Assert.Fail("ArgumentException not thrown");
}
}
示例4: StringTemplatStringAngleBracketsTest
public void StringTemplatStringAngleBracketsTest()
{
target = new StringTemplate("<hello> <world>");
target.Add("hello", "hello");
target.Add("<world>", "world");
Assert.AreEqual(2, target.ElementData.Count);
Assert.IsTrue(target.ElementData.ContainsKey("hello"));
Assert.AreEqual("hello", target.ElementData["hello"]);
Assert.IsTrue(target.ElementData.ContainsKey("world"));
Assert.AreEqual("world", target.ElementData["world"]);
Assert.AreEqual("hello world", target.Render());
}
示例5: StringTemplateRenderTwoElementTemplateTest
public void StringTemplateRenderTwoElementTemplateTest()
{
target = new StringTemplate("<test1> <test2> two");
target.Add("test1", "one");
target.Add("test2", "two");
Assert.AreEqual("one two two", target.Render());
}
示例6: StringTemplateRenderOneElementRepeatedTemplateTest
public void StringTemplateRenderOneElementRepeatedTemplateTest()
{
target = new StringTemplate("one <test> <test>");
target.Add("test", "two");
Assert.AreEqual("one two two", target.Render());
}
示例7: StringTemplateRenderNoDataForElementTest
public void StringTemplateRenderNoDataForElementTest()
{
target = new StringTemplate("<test> two two");
target.Add("testing", "one");
Assert.AreEqual("<test> two two", target.Render());
}
示例8: StringTemplateRenderExtraElementDataTest
public void StringTemplateRenderExtraElementDataTest()
{
target = new StringTemplate("<test> two two");
target.Add("test", "one");
target.Add("testing", "two");
Assert.AreEqual("one two two", target.Render());
}
示例9: StringTemplateRenderCaseInsensitiveTest2
public void StringTemplateRenderCaseInsensitiveTest2()
{
target = new StringTemplate("<TEST> two two");
target.Add("test", "one");
Assert.AreEqual("one two two", target.Render());
}
示例10: StringTemplateAddValueNullTest
public void StringTemplateAddValueNullTest()
{
target = new StringTemplate("test");
try
{
target.Add("test", null);
Assert.Fail("No exception thrown");
}
catch (ArgumentNullException exception)
{
Assert.AreEqual("value", exception.ParamName);
}
catch
{
Assert.Fail("ArgumentNullException not thrown");
}
}
示例11: StringTemplateAddTwoSameValuesTest
public void StringTemplateAddTwoSameValuesTest()
{
target = new StringTemplate(String.Empty);
target.Add("test", "one");
target.Add("testing", "one");
Assert.AreEqual(2, target.ElementData.Count);
Assert.IsTrue(target.ElementData.ContainsKey("test"));
Assert.AreEqual("one", target.ElementData["test"]);
Assert.IsTrue(target.ElementData.ContainsKey("testing"));
Assert.AreEqual("one", target.ElementData["testing"]);
}
示例12: StringTemplateAddElementWhitespaceTest
public void StringTemplateAddElementWhitespaceTest()
{
target = new StringTemplate("test");
try
{
target.Add(" ", new Object());
Assert.Fail("No exception thrown");
}
catch (ArgumentException exception)
{
Assert.AreEqual("The parameter 'element' cannot be an empty string.\r\nParameter name: element", exception.Message);
Assert.AreEqual("element", exception.ParamName);
}
catch
{
Assert.Fail("ArgumentException not thrown");
}
}