Coder Social home page Coder Social logo

Comments (6)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
(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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
This issue was closed by revision 1f24f2a60a25

Original comment by azizatif on 19 May 2015 at 4:52

  • Changed state: Fixed

from morelinq.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.