VB.NET+Quill+S2Dxoにて、PONO->IDictionaryの変換でハマったのでメモ
S2DxoのドキュメントだとDXOインターフェースに定義するメソッドでIDictionaryをそのまま使うように見えるが、これだとインスタンスが生成できずに例外が出る。Hashtableを使えばOK。.NETに精通してれば当たり前なのかも。
以下サンプル。
エンティティが、
Public Class AbcEntity Property Field1 As Integer Property Field2 As String End Class
データ交換オブジェクトインターフェースが、
Imports Seasar.Quill.Attrs <Implementation()> Public Interface IAbcEntityDxo <Aspect(GetType(Seasar.Dxo.Interceptor.DxoInterceptor))> Function ConvertToDictionary(ByVal aEntity As AbcEntity) As Hashtable End Interface
サービスインターフェースが、
Imports Seasar.Quill.Attrs <Implementation(GetType(AbcServiceImpl))> Public Interface IAbcServices Function Execute(ByVal aEntity As AbcEntity) As Hashtable End Interface
サービスクラスが、
Public Class AbcServiceImpl Implements IAbcServices Protected dxo As IAbcEntityDxo Public Overridable Function Execute(ByVal aEntity As AbcEntity) As IDictionary Implements IAbcServices.Execute Return dxo.ConvertToDictionary(aEntity) End Function End Class
フォームにQuillControlとButtonを1つおいて、
Public Class Form1 Protected service As IAbcServices Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'エンティティを作って、 Dim entity As New AbcEntity With {.Field1 = 1234, .Field2 = "Hello, world"} 'プロパティ名=値、のハッシュテーブルに変換し、 Dim dict As Hashtable = service.Execute(entity) 'ハッシュテーブルの中身を表示してみる。 For Each item As DictionaryEntry In dict MessageBox.Show(String.Format("Key={0}, Value={1}", item.Key, item.Value)) Next End Sub End Class
うまく動作しました。これで3時間も・・・くやしい!