c# - Get all property expressions from a type lambda expressions -


i want make htmlhelper can produce hidden fields properties of class.

in razor page call following:

@html.hiddenforobject(x=>x.someclass) 

where x model defined @model someotherclass

my helper defined such =>

public static mvchtmlstring hiddenforobject<tmodel, tproperty>(this htmlhelper<tmodel> htmlhelper,             expression<func<tmodel, tproperty>> expression) 

now class has few public properties want make hidden field for. here stuck need find right code iterate on properties in expression, expressions properties can call

//pseudo code foreach(var propertyexpression in expression) { @html.hiddenfor(expression); } 

i tried few things ran out of ideas. appreciated.

you can use reflection on expression

        foreach (var p in stage.gettype().getproperties())         {          } 

however, there rather large performance hit if did that, plus open whole can of security worms, if use class access database well.

you extend idea, though, , define attributes mark hidden fields, , use extension method pick them out.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -