If it helps, here's a test case which reproduces it for
MacroTestCase.cs.  I had a look but don't know how to fix it.

        /// <summary>
        /// Unable to pass a reference to an object's property as a
parameter to a macro and have
        /// that property dereferenced inside the macro.
        /// </summary>
        [Test]
        public void DereferenceMethod()
        {
            const string template = "#macro(derefprop $someparam)\r
\n"+
                                    //"PASSED $someparam\r\n"+
                                    "FOUND $what.ToUpper($someparam)"
+
                                    "#end\r\n" +
                                    "#derefprop($what.testproperty)\r
\n";

            StringWriter sw = new StringWriter();

            VelocityContext context = new VelocityContext();
            context.Put("what", new Whatever());

            bool success = ve.Evaluate(context, sw, "MacroTest1",
template);
            //System.Console.Write("== RESULTS ==\r\n"+sw.ToString());
            Assert.IsTrue(success, "Evaluation failed");
            Assert.AreEqual("FOUND HELLO THERE", sw.ToString());
        }

        public class Whatever
        {
            public String Testproperty
            {
                get { return "Hello There"; }
            }

            public String Toupper(String str)
            {
                if (str == null)
                {
                    return "(input is null)"; // for debugging
                }
                return str.ToUpper();
            }
        }

On Jun 22, 9:42 am, Mike Bridge <[email protected]> wrote:
> It doesn't look like it works---I think the dot is confusing the macro
> parser.  #urlencode("Test ${article}") will call the Article object's
> ToString() method, but #urlencode("Test ${article.linkurl}") works the
> same as without the curly braces.
>
> It's not a big deal, but it'd be nice if I could simplify the syntax
> (and the logic) for our graphic designers.
>
> -Mike
>
> On Jun 13, 8:02 am, Ricardo Lopes <[email protected]> wrote:
>
> > The few times I used macros I passed objects and accessed the object
> > properties inside the macro.
>
> > Try using the formal notation:
>
> > #urlencode(${article.linkurl})
> > #urlencode("Test ${article.linkurl}")
>
> > 2009/6/13 Jonathon Rossi <[email protected]>
>
> > > Macro's aren't really supported because there are quite a lot of issues
> > > with them.
>
> > > It would be less painful to create a helper class (which it looks like you
> > > already have) with the functionality of the macro, which also makes it
> > > testable.
>
> > > On Wed, Jun 10, 2009 at 4:11 AM, Mike Bridge <[email protected]>wrote:
>
> > >> Hi-
>
> > >> I was wondering if this should work:
>
> > >> #macro(urlencode $querystring)$nvurlutils.urlencode($querystring)#end
>
> > >>    #set($url = "Test $article.linkurl")
>
> > >>    Test 1: $nvurlutils.urlencode("Test $article.linkurl")
> > >>    Test 2: #urlencode($url)
> > >>    Test 3: #urlencode($article.linkurl)
> > >>    Test 4: #urlencode("Test $article.linkurl")
>
> > >> What I'm getting is:
>
> > >>     Test 1: Test+http%3a%2f%2fwww.google.ca%2fsearch%3fq%3dCastle
> > >>     Test 2: Test+http%3a%2f%2fwww.google.ca%2fsearch%3fq%3dCastle
> > >>     Test 3:
> > >>     Test 4: Test
>
> > >> Test 1 & 2 are as expected, but Test 3 & 4 don't seem to dereference
> > >> my object & data accessor inside the macro.
>
> > >> I'm wondering why I can't seem to pass in an object reference---is it
> > >> a scoping problem in the macro?   As I understand it, a macro
> > >> parameter is passed by name and is dereferenced inside the macro, but
> > >> for some reason it doesn't seem to be available there.
>
> > >> Thanks,
>
> > >> -Mike
>
> > > --
> > > Jono
>
> > --
>
> > Ricardo Lopes
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to