本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroup.RegisterRenderer方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroup.RegisterRenderer方法的具体用法?C# TemplateGroup.RegisterRenderer怎么用?C# TemplateGroup.RegisterRenderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr4.StringTemplate.TemplateGroup
的用法示例。
在下文中一共展示了TemplateGroup.RegisterRenderer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToListString
public static string ToListString(this IList list)
{
TemplateGroup group = new TemplateGroup();
group.DefineTemplate("listTemplate", "[<list:{x|<x>}; separator=\", \">]", new string[] { "list" });
group.RegisterRenderer(typeof(IList), new CollectionRenderer());
Template st = group.GetInstanceOf("listTemplate");
st.Add("list", list);
return st.Render();
}
示例2: ReplacePropertyTokensInGroups
public static string ReplacePropertyTokensInGroups(IEnumerable collection, string groupTemplate)
{
StringBuilder resultBuilder = new StringBuilder();
foreach (var listItem in collection)
{
//We need new template for every collection item so that sub collection items like registrants are cleaned up
TemplateGroup eventGroup = new TemplateGroup(TextTemplateUtils.DefaultTokenStartDelimiter, TextTemplateUtils.DefaultTokenEndDelimiter);
eventGroup.RegisterRenderer(typeof(string), new StringRenderer());
Template eventTemplate = new Template(eventGroup, groupTemplate);
AddPropertiesToTemplate(listItem, eventTemplate);
resultBuilder.Append(eventTemplate.Render(CultureInfo.InvariantCulture));
}
return resultBuilder.ToString();
}
示例3: GetTemplateGroup
protected TemplateGroup GetTemplateGroup(List<string> templateNames)
{
if (tg == null)
{
// combile the header and all .st files and load everything into a TemplateGroup
tg = new TemplateGroup();
foreach (var templateName in templateNames)
{
tg.ImportTemplates(GetTemplateGroupFromResource(templateName));
}
foreach (var type in attributeRenderers.Keys)
{
var renderer = attributeRenderers[type];
tg.RegisterRenderer(type, renderer);
}
}
return tg;
}
示例4: TestRendererWithFormatAndSeparatorAndNull
public void TestRendererWithFormatAndSeparatorAndNull()
{
string template =
"The names: <names; separator=\" and \", null=\"n/a\", format=\"upper\">";
TemplateGroup group = new TemplateGroup();
group.RegisterRenderer(typeof(string), new StringRenderer());
Template st = new Template(group, template);
List<string> names = new List<string>();
names.Add("ter");
names.Add(null);
names.Add("sriram");
st.Add("names", names);
string expecting = "The names: TER and N/A and SRIRAM";
string result = st.Render();
Assert.AreEqual(expecting, result);
}
示例5: TestRendererWithFormatAndSeparator
public void TestRendererWithFormatAndSeparator()
{
string template =
"The names: <names; separator=\" and \", format=\"upper\">";
TemplateGroup group = new TemplateGroup();
group.RegisterRenderer(typeof(string), new StringRenderer());
Template st = new Template(group, template);
st.Add("names", "ter");
st.Add("names", "tom");
st.Add("names", "sriram");
string expecting = "The names: TER and TOM and SRIRAM";
string result = st.Render();
Assert.AreEqual(expecting, result);
}
示例6: GetListRendererTemplateGroup
private static TemplateGroup GetListRendererTemplateGroup()
{
if (_listRendererTemplateGroup == null)
{
_listRendererTemplateGroup = new TemplateGroupString("AttributeRendererTemplates", Properties.Resources.AttributeRendererTemplates);
_listRendererTemplateGroup.RegisterRenderer(typeof(IEnumerable), new CollectionRenderer());
_listRendererTemplateGroup.RegisterTypeProxyFactory(typeof(IDictionary), new DictionaryTypeProxyFactory());
_listRendererTemplateGroup.RegisterTypeProxyFactory(typeof(Misc.Aggregate), new AggregateProxyFactory());
_listRendererTemplateGroup.RegisterTypeProxyFactory(typeof(Template), new TemplateProxyFactory(_listRendererTemplateGroup));
}
return _listRendererTemplateGroup;
}