2

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.

Community
  • 1
  • 1
Jerther
  • 5,240
  • 7
  • 35
  • 55

1 Answers1

3

Maybe you can try on Arguments instead of Members.

var body = exp.Body as NewExpression;
foreach (var member in body.Arguments)
{
    Console.WriteLine(member);
}

Output is:

dt.Second
dt.Hour
dt.Date.Day
Orace
  • 6,774
  • 25
  • 42