[stringtemplate-interest] Dynamic property names in StringTemplate v3.2 for .Net
Magdalin, Vlad
Vladimir_Magdalin at intuit.com
Fri Nov 20 15:25:49 PST 2009
Sam,
Perhaps I wrote too soon. I've been investigating this, and seems like a
very simple test of this passes:
var obj = new { Prop1 = "PROPERTY_1_VALUE", Prop2 = "PROPERTY_2_VALUE"
};
Antlr3.ST.StringTemplate template = new Antlr3.ST.StringTemplate("obj:
$obj$, obj.$propName$: $obj.(propName)$");
template.SetAttribute("obj", obj);
template.SetAttribute("propName", "Prop1");
string value = template.ToString();
Assert.IsTrue(value.Contains("obj.Prop1: PROPERTY_1_VALUE"));
So I'm still looking at what might be causing this to fail in my larger,
more complex templates. Sorry for the false alarm.
-Vlad
From: Magdalin, Vlad
Sent: Friday, November 20, 2009 3:07 PM
To: 'Sam Harwell'
Cc: 'stringtemplate-interest at antlr.org'
Subject: Dynamic property names in StringTemplate v3.2 for .Net
Hi Sam,
I've been evaluating your build of ST 3.2 for .Net, and have ran into
only one issue so far where it doesn't seem to be backwards compatible
with the 3.1 version.
Let's say I have a C# object with two properties Prop1 and Prop2, and I
pass the object to the template as view data as "myObj".
With the 3.1 version of ST, I was able to do something like this:
Template1.st
---------------------------------------
This is something from Template2: $Template2(myObj = myObj,
property="Prop1")$
---------------------------------------
Template2.st
---------------------------------------
The value of $property$ for this object is: $myObj.(property)$
---------------------------------------
The rendered output would include the actual value of the Prop1 property
of the myObj passed to ViewData. However, in ST 3.2 this doesn't seem
to work at all - it renders: "The value of Prop1 for this object is: "
However, if Template2.st contains $myObj.Prop1$, the value is rendered
as expected, but some of my templates call for this type of indirection
where it's convenient for the view to provide the property name to use.
Do you know if this is something that's supported by your port? Looks
like it's documented on the main Java documentation wiki
(http://www.antlr.org/wiki/display/ST/ST+condensed+--+Templates+and+expr
essions in the Expressions section).
I appreciate any help you can provide.
Thanks,
Vlad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20091120/134ef099/attachment.html
More information about the stringtemplate-interest
mailing list