本文整理汇总了C#中StringTemplate.SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# StringTemplate.SetAttribute方法的具体用法?C# StringTemplate.SetAttribute怎么用?C# StringTemplate.SetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringTemplate
的用法示例。
在下文中一共展示了StringTemplate.SetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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());
}
示例2: 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;
}
示例3: 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;
}
示例4: 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>");
}
示例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: 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);
}
}
}
示例7: ProxiedObjectsHandled
public void ProxiedObjectsHandled()
{
StringTemplate template = new StringTemplate("Testing $person.Name$");
ProxyGenerator generator = new ProxyGenerator();
object person = generator.CreateClassProxy(typeof(Person), new NothingInterceptor(), new object[] { "Sean" });
template.SetAttribute("person", person);
string result = template.ToString();
Assert.AreEqual("Testing Sean", result);
}
示例8: 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() );
}
示例9: 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() );
}
示例10: TestChangingAttrValueRepeatedTemplateApplicationToVector
public void TestChangingAttrValueRepeatedTemplateApplicationToVector()
{
StringTemplateGroup group = new StringTemplateGroup( "dummy", "." );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$item$</b>" );
StringTemplate italics = group.DefineTemplate( "italics", "<i>$it$</i>" );
StringTemplate members = new StringTemplate( group, "$members:bold(item=it):italics(it=it)$" );
members.SetAttribute( "members", "Jim" );
members.SetAttribute( "members", "Mike" );
members.SetAttribute( "members", "Ashar" );
//System.out.println("members="+members);
string expecting = "<i><b>Jim</b></i><i><b>Mike</b></i><i><b>Ashar</b></i>";
Assert.AreEqual( expecting, members.ToString() );
}
示例11: 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() );
}
示例12: TestTruncOp
public void TestTruncOp()
{
StringTemplate e = new StringTemplate(
"$trunc(names); separator=\", \"$"
);
e = e.GetInstanceOf();
e.SetAttribute( "names", "Ter" );
e.SetAttribute( "names", "Tom" );
e.SetAttribute( "names", "Sriram" );
string expecting = "Ter, Tom";
Assert.AreEqual( expecting, e.ToString() );
}
示例13: TestTemplateApplicationAsOptionValue
public void TestTemplateApplicationAsOptionValue()
{
StringTemplate st = new StringTemplate(
"Tokens : <rules; separator=names:{<it>}> ;",
typeof( AngleBracketTemplateLexer ) );
st.SetAttribute( "rules", "A" );
st.SetAttribute( "rules", "B" );
st.SetAttribute( "names", "Ter" );
st.SetAttribute( "names", "Tom" );
string expecting = "Tokens : ATerTomB ;";
Assert.AreEqual( expecting, st.ToString() );
}
示例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: PrepareElementTypes
private void PrepareElementTypes(StringTemplate stringTemplate, ICollection<ITypeInfo> typeGenerationInfos)
{
stringTemplate.SetAttribute("namespace", BaseNamespace);
foreach (ITypeInfo info in typeGenerationInfos)
{
stringTemplate.SetAttribute("types.{name,f}", nameConverter.ConvertTypeName(info.BaseName),"f ");
}
}