RegisterRenderer() public method

public RegisterRenderer ( System.Type attributeType, IAttributeRenderer renderer ) : void
attributeType System.Type
renderer IAttributeRenderer
return void
Esempio n. 1
0
 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();
 }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        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;
        }