Comments (6)
This is indeed a bug but meanwhile you might want use the following as a
workaround:
MoreLinq.MoreEnumerable.ToDataTable(l, p => p.X, p => p.Y);
Even once fixed, I think the above workaround will be the actual usage you want
since Point has an instance property of IsEmpty (in addition to X and Y) that
will get included as a column in the resulting DataTable.
Original comment by azizatif
on 18 May 2015 at 4:04
- Changed state: Accepted
from morelinq.
(fixing issue summary)
Original comment by azizatif
on 18 May 2015 at 4:41
- Changed title: ToDataTable throws on type with public static member
from morelinq.
The exception is thrown by Expression.Field and is a breaking change with .NET
4.x. On .NET 3.5, there is no exception thrown and DataTable is created with
static members also appearing as columns so perhaps this slipped unnoticed
previously.
System.ArgumentException : Static field requires null instance, non-static
field requires non-null instance.
Parameter name: expression
at System.Linq.Expressions.Expression.Field(Expression expression, FieldInfo field)
at System.Linq.Expressions.Expression.MakeMemberAccess(Expression expression, MemberInfo member)
at MoreLinq.MoreEnumerable.CreateMemberAccessor(Expression parameter, MemberInfo member) in ToDataTable.cs: line 142
Original comment by azizatif
on 18 May 2015 at 5:35
- Changed state: Started
- Added labels: Milestone-Release1.1-SP1, Priority-High
- Removed labels: Priority-Medium
from morelinq.
Few comments:
1. If there is a chance for a bug that only I will fall on, my life story is
that I will fall on it :-)
2. Indeed I could use your suggestion of specifying the parameters to render to
the data table but in my case this was just an example. I have a much larger
class that I need to render to a data table and if I add fields to the class I
now have to remember to add them to the rendering list of fields. Obviously I
would prefer to skip the need if possible.
3. on a more technical level, I have some old code that does about the same (I
prefer to use yours). The code is working and did not fail were yours did. use
it at your own will
Public Shared Function ToDataTable(Of T)(ByVal data As IList(Of T)) As DataTable
Dim properties As ComponentModel.PropertyDescriptorCollection = ComponentModel.TypeDescriptor.GetProperties(GetType(T))
Dim table As New DataTable()
For Each prop As ComponentModel.PropertyDescriptor In properties
table.Columns.Add(prop.Name, If(Nullable.GetUnderlyingType(prop.PropertyType), prop.PropertyType))
Next prop
If data IsNot Nothing Then
For Each item As T In data
If item IsNot Nothing Then
Dim row As DataRow = table.NewRow()
For Each prop As ComponentModel.PropertyDescriptor In properties
row(prop.Name) = If(prop.GetValue(item), DBNull.Value)
Next prop
table.Rows.Add(row)
End If
Next item
End If
Return table
End Function
Original comment by [email protected]
on 18 May 2015 at 7:19
from morelinq.
This issue was closed by revision 1f24f2a60a25
Original comment by azizatif
on 19 May 2015 at 4:52
- Changed state: Fixed
from morelinq.
Published as v1.1.1 (aka SP1) as well as source packages:
* https://www.nuget.org/packages/morelinq/1.1.1
*
https://www.nuget.org/packages/MoreLinq.Source.MoreEnumerable.ToDataTable/1.0.1
* https://www.nuget.org/packages/MoreLinq.Source.MoreEnumerable/1.2.1
Original comment by azizatif
on 19 May 2015 at 6:05
from morelinq.
Related Issues (20)
- Usage example for SingleOrFallback HOT 7
- converting IEnumerable<TSource> into IEnumerable<IEnumerable<TSource>>? HOT 1
- Buffering HOT 1
- Please make .NET 4 compatible distribution (or allow silent modifications)
- Interleave irregular enumerables with circular strategy HOT 4
- TakeLast example incorrect HOT 5
- Patch for /MoreLinq/DistinctBy.cs HOT 2
- Implement Full Outer Join
- ExpandoObject inclusion HOT 4
- Patch for /MoreLinq/EquiZip.cs
- Change ArgumentNullException to early return. HOT 1
- MaxByOrDefault HOT 2
- Scan should not throw on empty sequences
- Batch should return an IEnumerable<IList<T>> HOT 1
- Migrate to GitHub/BitBucket HOT 14
- add Memoize support HOT 1
- ForEach should optionally take an index HOT 2
- It would be nice to have a Top operator that would merge OrderBy and Take
- F# countBy analogue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from morelinq.