0

I get enumerable dynamic objects back from a database class which are declared like

IEnumerable<dynamic> sessions = null

I have an extended method that humanising datetimes, adding the day ordinals etc.

DateTime.Now.HumanisedDate()

This works find but I cant apply the extension method directly on the dynamic object

session.STARTDATE.HumanisedDate()

but GetType() for session.STARTDATE says System.DateTime

If I do this

DateTime whatever = session.STARTDATE;
whatever.HumanisedDate()

All is good. I'd like to understand why session.STARTDATE is reported as being a DateTime type but I cannot apply a DateTime extension to it. Thanks all.

Rolf Herbert
  • 45
  • 1
  • 8

1 Answers1

0

Will the dynamic keyword in C#4 support extension methods?

and

Extension method and dynamic object

Go into some detail about why extension methods are not available on dynamic objects.

Rolf Herbert
  • 45
  • 1
  • 8