Ognacの雑感

木漏れ日々

目次

Blog 利用状況

書庫

ギャラリ

リフレクションとジェネリックとBindingと

型定義されたレコード(*.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もコストが高い..ですがトレードオフで使いやすくなっているんですね。

 

投稿日時 : 2007年7月21日 21:43

Feedback

# Hi, i think that i saw you visited my weblog thus i came to go back the want?.I'm trying to in finding things to enhance my website!I guess its good enough to make use of some of your ideas!! 2019/04/11 4:35 Hi, i think that i saw you visited my weblog thus

Hi, i think that i saw you visited my weblog thus
i came to go back the want?.I'm trying to in finding things to enhance my website!I guess its good
enough to make use of some of your ideas!!

# Heya i am for the first time here. I found this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you aided me. 2019/07/31 20:50 Heya i am for the first time here. I found this bo

Heya i am for the first time here. I found this board and I find It
really useful & it helped me out much. I hope to give something back and aid
others like you aided me.

# Heya i am for the first time here. I found this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you aided me. 2019/07/31 20:51 Heya i am for the first time here. I found this bo

Heya i am for the first time here. I found this board and I find It
really useful & it helped me out much. I hope to give something back and aid
others like you aided me.

# Heya i am for the first time here. I found this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you aided me. 2019/07/31 20:52 Heya i am for the first time here. I found this bo

Heya i am for the first time here. I found this board and I find It
really useful & it helped me out much. I hope to give something back and aid
others like you aided me.

# Heya i am for the first time here. I found this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you aided me. 2019/07/31 20:53 Heya i am for the first time here. I found this bo

Heya i am for the first time here. I found this board and I find It
really useful & it helped me out much. I hope to give something back and aid
others like you aided me.

# re: ???????????????Binding? 2021/07/08 19:45 lupus wikipedia english

chloroguine https://chloroquineorigin.com/# hydroclorizine

# re: ???????????????Binding? 2021/07/24 22:52 hydroxychloroquine sulfate tablets

is chloroquine safe https://chloroquineorigin.com/# hydroxyquine side effects

# re: ???????????????Binding? 2021/08/08 2:39 hidroxicloroquina 400mg

malaria drug chloroquine https://chloroquineorigin.com/# chloroquine phosphate vs hydroxychloroquine

# chloroquine ph 500 mg tablet 2022/12/25 13:11 MorrisReaks

https://www.hydroxychloroquinex.com/# purchase plaquenil online

# hydroxychloroquine tablets for sale 2022/12/26 7:49 MorrisReaks

plaquenil tablets 200mg https://www.hydroxychloroquinex.com/#

# doors2.txt;1 2023/03/14 15:04 NiNRCBPMCd

doors2.txt;1

# ロレックスコピー 2023/05/28 16:53 coxAcquic

エルバーキンコピーエルメスバーキン30コピーエルメス ボリード47,エルメス バッグ 名前,エルメス ネクタイ ピンク エルメス クラッチバッグ,エルメス バッグ コピー,エルメス バーキン コピー エルメス 財布 ダミエ オークション,エルメス ヨーロッパ,エルメス エールライン エルメス クラッチ激安通販、高い品質、送料無料。バーキン25コピー、バーキン30コピー、バーキン35コピー }}}}}}
https://www.bagssjp.com/product/detail-6871.html
https://www.bagssjp.com/product/detail-9403.html
https://www.bagssjp.com/product/detail-765.html
https://www.bagssjp.com/product/detail-10457.html
https://www.bagssjp.com/product/detail-11871.html

タイトル
名前
Url
コメント