0

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.

Janus007
  • 366
  • 4
  • 11
  • 1
    See [this question](http://stackoverflow.com/questions/1718037/abuse-of-c-lambda-expressions-or-syntax-brilliance) which explains what is going on (and discusses if this is a good idea or not) – Cameron Oct 19 '10 at 20:41
  • .Attributes(style => "width:100%") I think it's another style, since you are not using a property here, but a style which is not strong typed anywhere. – Janus007 Oct 19 '10 at 21:14

1 Answers1

1

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
  • 59,176
  • 9
  • 122
  • 152
  • 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 Oct 19 '10 at 21:16
  • 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> predicate – Janus007 Oct 19 '10 at 21:55
  • 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 Oct 19 '10 at 22:05