c# - How can I avoid using a string member name to get a member of an anonymous type? -


I am using the following code to retrieve names of members in an unknown way. Can I change the follwing code to use the Lukada expression, or to allow at least the calling code to use Lambda, even if I have to use the 'deep down' string?

  Private Tee GetAnonymousTypeMember & lt; T & gt; (Object anonymous type, type member member name) where T: class {var anonTypesType = anonymousType.GetType (); Var propInfo = anonTypesType.GetProperty (memberName); Return ProofFo.Gate Value (anonymous type, empty) as T; }  Added:  How does  anonymous type  come in  GetAnonymousTypeMember  method is private for that class Only public law has been declared: 

Public Zero Publishing Notice (Notification Trigger Trigger, Object Template Parameter)

I call this method:

  Publish Notation (Notification.represented, New {NewJobCard = Model});   

That new {NewJobCard = model} is made as GetAnonymousTypeMember as anonymousType .

  & gt; selector ) {Type type = typef (t); Var expr = selector.Body as a member expression; String name = xp Member; name; Var prop = type.GetProperty (name); Return (U) prop.GetValue (example, zero); }  

will be able to do this:

  string name = GetMemberValue (new {name = "hello"}, o = & gt; o Name);  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -