views:

50

answers:

1

Hi There... Inspired by:
NServiceBus.Configure.With().Log4Net(a => a.YourProperty = "value");

I want to use something similar as configuration, suggestions are welcome. My biggest problem is that I can't quite figure out how to use the parameter input...

What exactly is going on here? NServiceBus uses Log4Net, as instance? set with YourProperty = value?

Please abstract from the NServiceBus etc. I've just provided that as foundation for the discussion.

+1  A: 

The lambda is creating an expression tree, which is not code but metadata about what the lambda shall do.

Therefore you can then "take apart" the lambda and see what properties, methods etc. would have been accessed on that instance (which never existed, since it is a definition only).

Google for "expression tree .net" and you'll find a lot of info on the topic.

Lucero
Hi Lucero, Thank you pointing me to a search engine called Google *whhoooo* What you told me I was fully aware of, but I was interested in knowing what the method looked like that actually could handle such input and how it handles it :)
Janus007
Hi Lucero...I think I begin to understand now... but I've a question though! How can I set the value? I have written expressions for, well years, kindof... but they uses an equal, this one uses property.Should it be something like: Expression<Func<TSource, string>> predicate
Janus007
Sorry if I posted something you already knew. Many people are not aware that lambdas are not compiled to IL code directly by the C# compiler, but that they in fact are an abstract syntax tree which can be parsed, modified and finally compiled to IL. As for accessing properties, have a look at http://msdn.microsoft.com/en-us/library/system.linq.expressions.expression.property.aspx (sorry, another lame link to MSDN ;) )
Lucero