[nem-en] Re: += Macro and delegates
Andrey Khropov
andrey.khropov at gmail.com
Fri Dec 8 22:58:46 CET 2006
Kamil Skalski wrote:
> Ok, I guess you would like to use existing transformation function you
> are writing, which performs
> TExpr -> CodeDomExpression
That's right. But first I want to make sure that it's a delegate attachment and
not an integer addition. I could have done this easily if e and method were
TExpr (just by inspecting their Type property) but with PExpr it's harder
without type information.
>
> We need to create following codedom structure:
>
> CodeAttachEventStatement (
> CodeEventReferenceExpression (
> CodeExpression targetObject,
> string eventName
> )
> CodeExpression listener
> )
Of course.
>
> So assuming we have
> TExpr.DefValIn (LocalVal ("_N_cached"), TExpr (this.button1) as t1,
> TExpr.Call (TExpr.MethodRef (TExpr (_N_cached), IMethod (add_Click) as
> m1), [ TExpr (System.EventHandler(this.button1_Click)) as listener ] )
Well, but I guess this is just a sketch. And the problem is that it depends on
a particular way "+=" is implemented today. One day optimizer may eliminate
unnecessary caching and this pattern won't work anymore.
>
> I would do:
>
> CodeAttachEventStatement (
> CodeEventReferenceExpression (
> texpr_to_codeexpr (t1),
> m1.Name.Substring (4)
> ),
> texpr_to_codeexpr (listener)
> )
Something like that but this will require a sort of pattern matching on
'expanded' like you wrote above.
> If you prefer to operate on PExpr,
I don't but I have to if I deal with 'original'
> then you should fetch method's name
> just like before, but
> use pexpr_to_codeexpr on respectively $e and $method
Well I use texpr_to_codeexpr everywhere. Making pexpr_to_codeexpr will more
than double almost the same code (And I don't need it anywhere else yet).
What I'm looking for is an easy way to perform PExpr -> TExpr conversion for
these relatively easy expressions for e and method given some context.
P.S. I see discussing such a subject in forum isn't interactive enough. Do you
mind if I contact you by Jabber/IRC/ICQ ?
--
AKhropov
More information about the devel-en
mailing list