型定義されたレコード(*.xsd)の代わりに、自前のBindingList機能を作成しているのですが、その過程で面白い事に気づきました。
Public Class orMapTable(Of T As New)
Inherits BindingList(Of T)
Implements IDisposable
Implements I_fld_no_vs_name
Implements I_orMapTable
:::
:::
End Class
と言う感じでBinding可能なクラスを作っていて出くわしたんですが、今頃気づいたんかいと突っ込まれそうですが...(^_^;)
Dim S_zc As New orMapTable()
のようにコードでinstanceを生成して
DataGridView.DataSource = S_zc という風に バインドすると動作する。
このクラスを
Dim obj As Object = asm.CreateInstance(className, True, flg, Nothing, arg, cult_info, Nothing)
のようにリフレクションででinstanceを生成して
DataGridView.DataSource = obj という風に バインドすると動作しない。
Public Class orMapTable
Inherits BindingList
:::
:::
End Class
のように非ジェネリックで規定すると
Dim S_zc As New orMapTable()
のようにコードでinstanceを生成して
DataGridView.DataSource = S_zc という風に バインドすると動作する。
(?) な感じなんです。原因は後日追究するとして、気づいたのはこのときの呼び出し履歴が
System.Reflection.TargetInvocationException: オブジェクト 'クラス' のプロパティ アクセサ '項目1' が以下の例外をスローしました
'オブジェクトがターゲットの型と一致しません。' ---> System.Reflection.TargetException: オブジェクトがターゲットの型と一致しません。
場所 System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
場所 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
場所 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
場所 System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
場所 System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
場所 System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex)
となっている。 DataGridViewなどのBinding機能はリフレクション経由で動作してるんですね。全然意識してませんでした。コストの高い処理なんですね。<==イマゴロ気づくな 俺
DataTableも大きいクラスだし、DataGridViewもコストが高い..ですがトレードオフで使いやすくなっているんですね。