PLEASE CORRECT ME IF I AM WRONG – I WANT TO BE WRONG
I have tried to figure out how to do this in python and ruby and I just can’t seem to find the right libs.
public class Helper
{
public static void ExploreAst<T>(Expression<Function<T, object>> expression)
{
// do stuff with the AST
}
}
//later
Helper.ExploreAst<object>(o=>o.ToString());
If I try to do this in python, no bueno.
class MyObj(Class):
def my_method()
pass
def exploreAst(expression):
#do stuff with ast
pass
# later
exploreAst(MyObj.my_method)
#boom!
Why boom? Because python is a lossy language. Once it has been compiled you lose some of the sweet sauce of python that .net will still maintain. There are a few libraries that try to help you out. What’s even worse is that you can’t do this with fields in python because (duh!) it passes in the VALUE of the field. After all, python has no idea that you don’t want the value. Honestly, my guess is that this is not the best way to approach the problem in python. Big surprise here: I am being the guy that is trying to fit a square peg in a round hole and wondering why it doesn’t work. Silly me.
Anyone have any ideas, I really like the Fluent NHibernate mapping model and would love to bring it to other languages.
-d