AndreyBogach / morelinq

Automatically exported from code.google.com/p/morelinq
Apache License 2.0
0 stars 0 forks source link

ExpandoObject inclusion #93

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Abstract out the reflection process which can test to see if T is 
IDynamicMetaObjectProvider
2.
3.

What is the expected output? What do you see instead?
Expected - is a filled DataTable 
Instead - blank (since expando object via reflection has no properties)

What version of the product are you using? On what operating system?
Version - 2.0.0-alpha01(Prerelease)
OS - Windows 8

Please provide any additional information below.

Original issue reported on code.google.com by Yakru...@gmail.com on 23 Sep 2014 at 6:18

GoogleCodeExporter commented 8 years ago
I'm guessing you're talking about MoreEnumerable.ToDataTable methods. If so, I 
think this will overload the functionality unnecessarily when the desired 
effect can be achieved already by projecting the dynamic object to an anonymous 
one, with strong-typed and bound members, before calling ToDataTable. For 
example:

dynamic pt1 = new ExpandoObject();
pt1.X = 123;
pt1.Y = 456;
dynamic pt2 = new ExpandoObject();
pt2.X = 456;
pt2.Y = 789;
var points =
    from pt in new[] { pt1, pt2 }
    select new { X = pt.X * 2, 
                 Y = pt.Y * 3 };
points.ToDataTable();    

Original comment by azizatif on 23 Sep 2014 at 10:02

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi thanks for responding so fast.

Your answer will only work if at compile time you knew the fields that would 
exist. In the instance I am dealing with I'm generating the object at runtime 
by using a method to merge 2 objects Tuple<T1,T2> into a single dynamic/expando 
object.

Thanks

Original comment by Yakru...@gmail.com on 23 Sep 2014 at 10:32

GoogleCodeExporter commented 8 years ago
True but if you don't know the properties all you can do at run-time with 
IDynamicMetaObjectProvider at runtime is discover the property names and their 
values, but cannot know the types of the properties in advance. Without the 
types, all columns of such a DataTable would be of type System.Object, which I 
think is odd. Moreover, a sequence of dynamics, or just objects for that 
matter, don't have to be the same type! As a result, the DataTable cannot be 
said to have a uniform schema. MoreEnumerable.ToDataTable like many other 
methods in LINQ are designed to work over a sequence of homogenous objects of 
some type T. If T is dynamic, that's no different than object and a sequence of 
such would have to be assumed to be heterogeneous. Even in LINQ, if you have 
IEnumerable, you have to go over Enumerable.Cast<T> before you can benefit from 
any of the other standard query operators.

Original comment by azizatif on 23 Sep 2014 at 11:09