nhibernate - Generic Functions in VB.NET -
i'm not familiar generics (concept or syntax) in general (short of using them in collections , not), wondering if following best way of accomplishing want. actually, i'm not entirely positive generics solve problem in case.
i've modelled , mapped few dozen objects in nhibernate, , need sort of universal class crud operations instead of creating seperate persister class each type.. such as
sub update(someobject object, objecttype string) dim session isession = nhibernatehelper.opensession dim transaction itransaction = session.begintransaction session.update(ctype(someobject, objecttype)) transaction.commit() end sub
where someobject can different types. know isn't best way of doing (or if it'll work) i'm hoping can steer me in right direction.
the key issue here is: session.update take parameter? if session.update allows generic object, i'd use that:
sub update(of t)(byval someobject t) dim session isession = nhibernatehelper.opensession dim transaction itransaction = session.begintransaction session.update(someobject) transaction.commit() end sub
that'll flow generic type t through session.update.
if session.update takes object, pass in object; no need ctype it. additionally, if objecttype (string) type name of current object, you'd better off using someobject.gettype() in first place.
Comments
Post a Comment