Return-Path: Delivered-To: apmail-ibatis-user-cs-archive@www.apache.org Received: (qmail 44156 invoked from network); 20 Jan 2006 21:56:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Jan 2006 21:56:11 -0000 Received: (qmail 56815 invoked by uid 500); 20 Jan 2006 21:54:17 -0000 Delivered-To: apmail-ibatis-user-cs-archive@ibatis.apache.org Received: (qmail 56086 invoked by uid 500); 20 Jan 2006 21:54:12 -0000 Mailing-List: contact user-cs-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-cs@ibatis.apache.org Delivered-To: mailing list user-cs@ibatis.apache.org Received: (qmail 54485 invoked by uid 99); 20 Jan 2006 21:54:02 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2006 13:54:01 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of mike.schall@gmail.com designates 64.233.162.201 as permitted sender) Received: from [64.233.162.201] (HELO zproxy.gmail.com) (64.233.162.201) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2006 13:18:04 -0800 Received: by zproxy.gmail.com with SMTP id x7so545311nzc for ; Fri, 20 Jan 2006 13:17:44 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=P3oht1gwe3ggYD+C8u5v6yMUGzp8Ds+fZ0LO6m8zkBgUxDlm4LMlh9ol33IO29NSKp/ta1Hni+cyfiLFEFVHrHeBbyn6VqCcPOzOq+wYCmgCkTemEQ18cCLpowZBvtgWImUNTmXSUaJWqOah0iDia0qGYXXp+8YZXblGovpMehQ= Received: by 10.37.20.30 with SMTP id x30mr1779594nzi; Fri, 20 Jan 2006 13:17:43 -0800 (PST) Received: by 10.36.153.9 with HTTP; Fri, 20 Jan 2006 13:17:43 -0800 (PST) Message-ID: <5f9068320601201317v6a12e7c4m8b629e65f17501d2@mail.gmail.com> Date: Fri, 20 Jan 2006 15:17:43 -0600 From: Michael Schall To: user-cs@ibatis.apache.org Subject: Re: .NET 2.0 and Generics In-Reply-To: <9E60A7FA5322F841856BE6E670F3E7B61117DA4C@CPREXN020-EVS.itdmis02.futureshop.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <9E60A7FA5322F841856BE6E670F3E7B61117DA4C@CPREXN020-EVS.itdmis02.futureshop.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N I would agree. I want generic support. These should help you get by till then... Public Function Load(Of T As New)( _ ByVal queryName As String, _ ByVal parameters As IDictionary(Of String, Object)) As T =09Dim mapper As SqlMapper =3D DatabaseManager.Instance() =09Dim rv As T =09rv =3D DirectCast(mapper.QueryForObject(queryName, DirectCast(parameters, Object)) =09Return rv End Function Public Function Enumerate(Of T As New)( _ ByVal queryName As String, _ ByVal parameters As IDictionary(Of String, Object)) As IEnumerable(Of T) =09Dim mapper As SqlMapper =3D DatabaseManager.Instance() =09Dim collector As TypedEnumerateCollector(Of T) =3D New TypedEnumerateCollector(Of T) =09mapper.QueryWithRowDelegate(queryName, parameters, New SqlMapper.RowDelegate(AddressOf collector.Collect)) =09Return collector.Collected() End Function Private Class TypedEnumerateCollector(Of T) =09Private _list As IList(Of T) =09Public Sub New() =09=09_list =3D New List(Of T) =09End Sub =09Public Sub Collect(ByVal rowObject As Object, ByVal parameterObject As Object, ByVal junkList As IList) =09=09_list.Add(DirectCast(rowObject, T)) =09End Sub =09Public Function Collected() As IEnumerable(Of T) =09=09Return _list =09End Function End Class Public Function Map(Of Tk, Tv As New)( _ ByVal queryName As String, _ ByVal parameters As IDictionary(Of String, Object), _ ByVal keySel As KeySelector(Of Tk, Tv)) As IDictionary(Of Tk, Tv) =09Dim mapper As SqlMapper =3D DatabaseManager.Instance() =09Dim collector As TypedMapCollector(Of Tk, Tv) =3D New TypedMapCollector(Of Tk, Tv)(keySel) =09mapper.QueryWithRowDelegate(queryName, parameters, New SqlMapper.RowDelegate(AddressOf collector.Collect)) =09Return collector.Collected() End Function Public Delegate Function KeySelector(Of Tk, Tv)(ByVal v As Tv) As Tk Private Class TypedMapCollector(Of Tk, Tv) =09Private _map As IDictionary(Of Tk, Tv) =09Private _keySelector As KeySelector(Of Tk, Tv) =09Public Sub New(ByVal keySel As KeySelector(Of Tk, Tv)) =09=09_map =3D New Dictionary(Of Tk, Tv) =09=09_keySelector =3D keySel =09End Sub =09Public Sub Collect(ByVal rowObject As Object, ByVal parameterObject As Object, ByVal junkList As IList) =09=09Dim v As Tv =3D DirectCast(rowObject, Tv) =09=09Dim k As Tk =3D _keySelector(v) =09=09_map.Add(k, v) =09End Sub =09Public Function Collected() As IDictionary(Of Tk, Tv) =09=09Return _map =09End Function End Class