mgravell / fast-member

Automatically exported from code.google.com/p/fast-member
Apache License 2.0
1.03k stars 139 forks source link

ObjectReader.Create(List(of Object)) fails #67

Open danj1980 opened 5 years ago

danj1980 commented 5 years ago

Works great when I pass List(Of StronglyTypedObjectClass).

But when I pass a List(Of Object), it fails to return valid content and doesn't throw any exceptions, such as a NotSupportedException.

Dim NewCDRs As New List(Of object)
Dim NewCDR As New CustomerContractCall
NewCDR.Property1 = something
NewCDRs.Add(NewCDR)
Dim Reader = FastMember.ObjectReader.Create(NewCDRs)

If Reader.FieldCount = 0 Then
   Throw New System.Exception("This shouldn't happen")
End If
mgravell commented 5 years ago

What behaviour would you expect in this scenario? Object has zero public readable properties, etc...

On Tue, 8 Jan 2019, 18:52 danj1980 <notifications@github.com wrote:

Works great when I pass List(Of StronglyTypedObjectClass).

But when I pass a List(Of Object), it fails to return valid content and doesn't throw any exceptions, such as a NotSupportedException.

Dim NewCDRs As New List(Of object) Dim NewCDR As New CustomerContractCall NewCDR.Property1 = something NewCDRs.Add(NewCDR) Dim Reader = FastMember.ObjectReader.Create(NewCDRs)

If Reader.FieldCount = 0 Then Throw New System.Exception("This shouldn't happen") End If

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mgravell/fast-member/issues/67, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsJoiVV3V9HWEDiH4kw6L8ATjL3bEks5vBOjogaJpZM4Z2EQN .

danj1980 commented 5 years ago

For background, here is how I'm using it... I've got a function that takes a Linq2SQL DataContext and a Type, and submits the changes using SQLBulkCopy, instead of SubmitChanges(). Public Function PerformBulkInsert(DB As DataContext, TypeToInsert As Type) As the function can be called with any TypeToInsert, I had to use a List(of Object) within the function to store the relevant objects from DB.GetChangeSet.Inserts that are the matching type.

I've since discovered that, since I'm passing in the Type of objects that the function should submit, I can use New FastMember.ObjectReader(GetType(TypeToInsert), Objects) as a solution.

What behaviour would you expect in this scenario? Object has zero public readable properties, etc...

Unless there is a case where ObjectReader would be successfully used with Object, I was expecting that Create<T>(IEnumerable<T> source, params string[] members) would throw a NotSupportedExpection if T is Object. Instead it returned an unusable Reader (unuseable in my case), so SqlBulkCopy.WriteToServer(Reader) silently made no SQL DB changes.