本文整理汇总了C#中StringTemplate.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# StringTemplate.ToString方法的具体用法?C# StringTemplate.ToString怎么用?C# StringTemplate.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringTemplate
的用法示例。
在下文中一共展示了StringTemplate.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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());
}
示例3: 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;
}
示例4: 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;
}
示例5: 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.");
}
示例6: 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>");
}
示例7: 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");
}
示例8: TestCombinedOp
public void TestCombinedOp()
{
// replace first of yours with first of mine
StringTemplate e = new StringTemplate(
"$[first(mine),rest(yours)]; separator=\", \"$"
);
e = e.GetInstanceOf();
e.SetAttribute( "mine", "1" );
e.SetAttribute( "mine", "2" );
e.SetAttribute( "mine", "3" );
e.SetAttribute( "yours", "a" );
e.SetAttribute( "yours", "b" );
string expecting = "1, b";
Assert.AreEqual( expecting, e.ToString() );
}
示例9: TestCollectionAttributes
public void TestCollectionAttributes()
{
StringTemplateGroup group =
new StringTemplateGroup( "test" );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$it$</b>" );
StringTemplate t =
new StringTemplate( group, "$data$, $data:bold()$, " +
"$list:bold():bold()$, $array$, $a2$, $a3$, $a4$" );
List<object> v = new List<object>();
v.Add( "1" );
v.Add( "2" );
v.Add( "3" );
IList list = new List<object>();
list.Add( "a" );
list.Add( "b" );
list.Add( "c" );
t.SetAttribute( "data", v );
t.SetAttribute( "list", list );
t.SetAttribute( "array", new string[] { "x", "y" } );
t.SetAttribute( "a2", new int[] { 10, 20 } );
t.SetAttribute( "a3", new float[] { 1.2f, 1.3f } );
t.SetAttribute( "a4", new double[] { 8.7, 9.2 } );
//System.out.println(t);
string expecting = "123, <b>1</b><b>2</b><b>3</b>, " +
"<b><b>a</b></b><b><b>b</b></b><b><b>c</b></b>, xy, 1020, 1.21.3, 8.79.2";
Assert.AreEqual( expecting, t.ToString() );
}
示例10: TestChangingAttrValueTemplateApplicationToVector
public void TestChangingAttrValueTemplateApplicationToVector()
{
StringTemplateGroup group =
new StringTemplateGroup( "test" );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$x$</b>" );
StringTemplate t = new StringTemplate( group, "$names:bold(x=it)$" );
t.SetAttribute( "names", "Terence" );
t.SetAttribute( "names", "Tom" );
//System.out.println("'"+t.toString()+"'");
string expecting = "<b>Terence</b><b>Tom</b>";
Assert.AreEqual( expecting, t.ToString() );
}
示例11: TestUnicodeLiterals
public void TestUnicodeLiterals()
{
StringTemplate st = new StringTemplate(
"Foo <\\uFEA5\\n\\u00C2> bar" + newline,
typeof( AngleBracketTemplateLexer )
);
string expecting = "Foo \xfea5" + newline + "\x00C2 bar" + newline;
string result = st.ToString();
Assert.AreEqual( expecting, result );
st = new StringTemplate(
"Foo $\\uFEA5\\n\\u00C2$ bar" + newline );
expecting = "Foo \xfea5" + newline + "\x00C2 bar" + newline;
result = st.ToString();
Assert.AreEqual( expecting, result );
st = new StringTemplate(
"Foo$\\ $bar$\\n$" );
expecting = "Foo bar" + newline;
result = st.ToString();
Assert.AreEqual( expecting, result );
}
示例12: GetTemplate
private string GetTemplate(string templateSlug)
{
var template = new StringTemplate(_contentRepository.Get(templateSlug, "email-template").ContentText);
return template.ToString();
}
示例13: CleanJSON
public string CleanJSON(StringTemplate json)
{
return Regex.Replace(json.ToString(), @",(\s*)([\},\]])", @"$1$2", RegexOptions.Multiline);
}
示例14: TestCatListAndSingleAttribute
public void TestCatListAndSingleAttribute()
{
// replace first of yours with first of mine
StringTemplate e = new StringTemplate(
"$[mine,yours]; separator=\", \"$"
);
e = e.GetInstanceOf();
e.SetAttribute( "mine", "1" );
e.SetAttribute( "mine", "2" );
e.SetAttribute( "mine", "3" );
e.SetAttribute( "yours", "a" );
string expecting = "1, 2, 3, a";
Assert.AreEqual( expecting, e.ToString() );
}
示例15: TestCatListAndEmptyAttributes
public void TestCatListAndEmptyAttributes()
{
// + is overloaded to be cat strings and cat lists so the
// two operands (from left to right) determine which way it
// goes. In this case, x+mine is a list so everything from their
// to the right becomes list cat.
StringTemplate e = new StringTemplate(
"$[x,mine,y,yours,z]; separator=\", \"$"
);
e = e.GetInstanceOf();
e.SetAttribute( "mine", "1" );
e.SetAttribute( "mine", "2" );
e.SetAttribute( "mine", "3" );
e.SetAttribute( "yours", "a" );
string expecting = "1, 2, 3, a";
Assert.AreEqual( expecting, e.ToString() );
}