本文整理汇总了C#中Antlr3.ST.StringTemplateGroup.DefineTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# StringTemplateGroup.DefineTemplate方法的具体用法?C# StringTemplateGroup.DefineTemplate怎么用?C# StringTemplateGroup.DefineTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.ST.StringTemplateGroup
的用法示例。
在下文中一共展示了StringTemplateGroup.DefineTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMultipleAdditions
public void TestMultipleAdditions()
{
// specify a template to apply to an attribute
// Use a template group so we can specify the start/stop chars
StringTemplateGroup group =
new StringTemplateGroup( "dummy", "." );
group.DefineTemplate( "link", "<a href=\"$url$\"><b>$title$</b></a>" );
StringTemplate duh =
new StringTemplate( group,
"$link(url=\"/member/view?ID=\"+ID+\"&x=y\"+foo, title=\"the title\")$" );
duh.SetAttribute( "ID", "3321" );
duh.SetAttribute( "foo", "fubar" );
string expecting = "<a href=\"/member/view?ID=3321&x=yfubar\"><b>the title</b></a>";
Assert.AreEqual( expecting, duh.ToString() );
}
示例2: 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() );
}
示例3: TestBackslash2
public void TestBackslash2()
{
StringTemplateGroup group = new StringTemplateGroup("test");
StringTemplate t = group.DefineTemplate("t", "\\ ");
string expecting = "\\ ";
Assert.AreEqual(expecting, t.ToString());
}
示例4: TestTemplatePolymorphism
public void TestTemplatePolymorphism()
{
StringTemplateGroup group = new StringTemplateGroup( "super" );
StringTemplateGroup subGroup = new StringTemplateGroup( "sub" );
subGroup.SuperGroup = group;
// bold is defined in both super and sub
// if you create an instance of page via the subgroup,
// then bold() should evaluate to the subgroup not the super
// even though page is defined in the super. Just like polymorphism.
group.DefineTemplate( "bold", "<b>$it$</b>" );
group.DefineTemplate( "page", "$name:bold()$" );
subGroup.DefineTemplate( "bold", "<strong>$it$</strong>" );
StringTemplate st = subGroup.GetInstanceOf( "page" );
st.SetAttribute( "name", "Ter" );
string expecting =
"<strong>Ter</strong>";
Assert.AreEqual( expecting, st.ToString() );
}
示例5: TestTemplateApplicationAsRHSOfAssignment
public void TestTemplateApplicationAsRHSOfAssignment()
{
StringTemplateGroup group = new StringTemplateGroup( "test" );
StringTemplate hostname = group.DefineTemplate( "hostname", "$machine$.jguru.com" );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$x$</b>" );
StringTemplate italics = group.DefineTemplate( "italics", "<i>$it$</i>" );
StringTemplate t = new StringTemplate( group, "$bold(x=hostname(machine=\"www\"):italics())$" );
string expecting = "<b><i>www.jguru.com</i></b>";
Assert.AreEqual( expecting, t.ToString() );
}
示例6: TestStringLiteralAsAttribute
public void TestStringLiteralAsAttribute()
{
StringTemplateGroup group = new StringTemplateGroup( "test" );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$it$</b>" );
StringTemplate name = new StringTemplate( group, "$\"Terence\":bold()$" );
Assert.AreEqual( "<b>Terence</b>", name.ToString() );
}
示例7: TestStringCatenationOnSingleValuedAttributeViaTemplateLiteral
public void TestStringCatenationOnSingleValuedAttributeViaTemplateLiteral()
{
StringTemplateGroup group =
new StringTemplateGroup( "test" );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$it$</b>" );
//StringTemplate a = new StringTemplate(group, "$\" Parr\":bold()$");
StringTemplate b = new StringTemplate( group, "$bold(it={$name$ Parr})$" );
//a.SetAttribute("name", "Terence");
b.SetAttribute( "name", "Terence" );
string expecting = "<b>Terence Parr</b>";
//Assert.AreEqual(a.toString(), expecting);
Assert.AreEqual( b.ToString(), expecting );
}
示例8: TestParameterAndAttributeScoping
public void TestParameterAndAttributeScoping()
{
StringTemplateGroup group =
new StringTemplateGroup( "test" );
StringTemplate italics = group.DefineTemplate( "italics", "<i>$x$</i>" );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$x$</b>" );
StringTemplate t = new StringTemplate( group, "$bold(x=italics(x=name))$" );
t.SetAttribute( "name", "Terence" );
//System.out.println(t);
string expecting = "<b><i>Terence</i></b>";
Assert.AreEqual( expecting, t.ToString() );
}
示例9: TestApplyRepeatedAnonymousTemplateWithForeignTemplateRefToMultiValuedAttribute
public void TestApplyRepeatedAnonymousTemplateWithForeignTemplateRefToMultiValuedAttribute()
{
// specify a template to apply to an attribute
// Use a template group so we can specify the start/stop chars
StringTemplateGroup group =
new StringTemplateGroup( "dummy", "." );
group.DefineTemplate( "link", "<a href=\"$url$\"><b>$title$</b></a>" );
StringTemplate duh =
new StringTemplate( group,
"start|$p:{$link(url=\"/member/view?ID=\"+it.ID, title=it.firstName)$ $if(it.canEdit)$canEdit$endif$}:" +
"{$it$<br>\n}$|end" );
duh.SetAttribute( "p", new Connector() );
duh.SetAttribute( "p", new Connector2() );
//System.out.println(duh);
string expecting = "start|<a href=\"/member/view?ID=1\"><b>Terence</b></a> <br>" + newline +
"<a href=\"/member/view?ID=2\"><b>Tom</b></a> canEdit<br>" + newline +
"|end";
Assert.AreEqual( expecting, duh.ToString() );
}
示例10: TestNullValueInListWithTemplateApplyNullFirstValue
public void TestNullValueInListWithTemplateApplyNullFirstValue()
{
StringTemplateGroup group =
new StringTemplateGroup( "test", typeof( AngleBracketTemplateLexer ) );
StringTemplate t =
group.DefineTemplate( "t", "<data:array(); null=\"-1\", separator=\", \">" );
group.DefineTemplate( "array", "<it>" );
IList data = new List<object>();
data.Add( null );
data.Add( 0 );
data.Add( null );
data.Add( 2 );
t.SetAttribute( "data", data );
string expecting = "-1, 0, -1, 2";
Assert.AreEqual( expecting, t.ToString() );
}
示例11: TestNullValueInListNoNullOption
public void TestNullValueInListNoNullOption()
{
StringTemplateGroup group =
new StringTemplateGroup( "test", typeof( AngleBracketTemplateLexer ) );
StringTemplate t =
group.DefineTemplate( "t", "<data; separator=\", \">" );
IList data = new List<object>();
data.Add( null );
data.Add( 1 );
data.Add( null );
data.Add( 3 );
data.Add( 4 );
data.Add( null );
t.SetAttribute( "data", data );
//System.out.println(t);
string expecting = "1, 3, 4";
Assert.AreEqual( expecting, t.ToString() );
}
示例12: TestNullSingleValueWithTemplateApply
public void TestNullSingleValueWithTemplateApply()
{
StringTemplateGroup group =
new StringTemplateGroup( "test", typeof( AngleBracketTemplateLexer ) );
StringTemplate t =
group.DefineTemplate( "t", "<data:array(); null=\"-1\", separator=\", \">" );
group.DefineTemplate( "array", "<it>" );
string expecting = "-1";
Assert.AreEqual( expecting, t.ToString() );
}
示例13: TestNullOptionSingleNullValue
public void TestNullOptionSingleNullValue()
{
StringTemplateGroup group =
new StringTemplateGroup( "test", typeof( AngleBracketTemplateLexer ) );
StringTemplate t =
group.DefineTemplate( "t", "<data; null=\"0\">" );
//System.out.println(t);
string expecting = "0";
Assert.AreEqual( expecting, t.ToString() );
}
示例14: TestNullOptionHasEmptyNullValue
public void TestNullOptionHasEmptyNullValue()
{
StringTemplateGroup group =
new StringTemplateGroup( "test", typeof( AngleBracketTemplateLexer ) );
StringTemplate t =
group.DefineTemplate( "t", "<data; null=\"\", separator=\", \">" );
IList data = new List<object>();
data.Add( null );
data.Add( 1 );
t.SetAttribute( "data", data );
string expecting = ", 1";
Assert.AreEqual( expecting, t.ToString() );
}
示例15: TestApplyTemplateToSingleValuedAttributeWithDefaultAttribute
public void TestApplyTemplateToSingleValuedAttributeWithDefaultAttribute()
{
StringTemplateGroup group = new StringTemplateGroup( "test" );
StringTemplate bold = group.DefineTemplate( "bold", "<b>$it$</b>" );
StringTemplate name = new StringTemplate( group, "$name:bold()$" );
name.SetAttribute( "name", "Terence" );
Assert.AreEqual( "<b>Terence</b>", name.ToString() );
}