简体   繁体   中英

Different behaviours between .NET 4.0 beta 2 and last release of .NET 4.0?

I've identified a difference of DLR between .NET 4.0 Beta 2 and the last release of .NET 4.0.

In .NET 4.0 Beta 2, this code perfectly works at runtime :

 var dateTimeList = new List<DateTime>(); 
 dynamic myDynamicObject = dateTimeList;
 object value = DateTime.Now;
 myDynamicObject.Add(value);

Now, with last release of .NET 4.0, I have an exception at run time (to solve myDynamicObject.Add(value);) :-(

In my real code, 'myDynamicObject' is a dynamic (but I know that it is always an ObservableCollection where T can be anything). 'value' is an instance which was got by some reflexions. As 'value' can have any type, the type of 'value' is Object.

Do you see how can I solve this new limitation of .NET 4.0 ?

Thanks

If you change the type of value to dynamic it works fine. (assuming dateTimeList is List<DateTime> ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM