[stringtemplate-interest] Capturing evaluated attributes
Scott Waye
scott.waye at hubse.com
Fri Nov 20 14:48:40 PST 2009
Hi,
I want to capture all evaluated attributes, and some summary about how
they expanded (null, empty string, or not null). So I subclassed
StringTemplate with this:
public class HostTemplate : StringTemplate
{
public class AttributeExpansion
{
public string Name { get; set; }
public object Result { get; set; }
}
public List<string> NullAttributes = new List<string>();
public List<string> EmptyStringAttributes = new List<string>();
public List<AttributeExpansion> ExpandedAttributes = new
List<AttributeExpansion>();
public HostTemplate(string template) : base(template)
{
}
public override object GetAttribute(string name)
{
var res = base.GetAttribute(name);
if(res == null)
{
NullAttributes.Add(name);
}
else if(res is string && ((string)res) == "")
{
EmptyStringAttributes.Add(name);
}
else
{
ExpandedAttributes.Add(new AttributeExpansion {Name =
name, Result = res});
}
return res;
}
}
Seems to work, at least on simple templates. Does this look OK, or have
I reinvented a wheel that I've missed?
--
Scott
More information about the stringtemplate-interest
mailing list