mardi 29 décembre 2015

C#: Getting Names of properties in a chain from NewExpression members

Suppose this expression:

Expression<Func<DateTime, dynamic>> exp = dt => new { dt.Second, dt.Hour, dt.Date.Day };

I need to obtain the following: "Second", "Hour", "Date.Day"

The best I've been able to accomplish is the following:

var body = exp.Body as NewExpression;
foreach(var member in body.Members)
    member.Name().Dump();

But I only get: "Second", "Hour", "Day"


This is somewhat similar to this question but I'm dealing with a NewExpression here.





Aucun commentaire:

Enregistrer un commentaire