c# - Get value from ASP.NET MVC Lambda Expression -


i trying create own html helper takes in expression (similar built-in labelfor<> helper. have found examples obtain value of property when expression similar this:

model => model.forename 

however, in of models, want obtain properties in child elements, e.g.

model => mode.person.forename 

in these examples, cannot find anyway (easily) obtain value of forename. can advise on how should getting value.

thanks

if using same pattern labelfor<> method uses, expression lambdaexpression , can execute value.

var result = ((lambdaexpression)expression).compile().dynamicinvoke(model); 

generally, can wrap generic expressions in lambdaexpressions , compile & invoke them value.

if want isn't value of forename, field (fx. print out string "forename") option use form of expressionwalking. in c#4 framework provides class called expressionvisitor can used this, earlier versions of framework have implement - see: http://msdn.microsoft.com/en-us/library/bb882521(vs.90).aspx


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -