c# - Generics - Passing instances as a base type -



c# - Generics - Passing instances as a base type -

i'm working on info access layer our new application, it's not big application i've decided go dao pattern, converting each model item dao item before storing database through stored queries. much possible of i've used generic interfaces , abstract classes remove repetitive operations i've nail bit of road block. have interface dao conversion classes looking following:

internal interface idaoconverter<tmodel, tdao> tmodel : modelitem tdao : daoitem { todao(tmodel inmodel); indao); }

this works fine far , fits it's function, specify model type , dao type converted (1-1 relationship) in class definition , functions created match these types. instances of these dao converters held in mill create retrieval easier.

the next thing want create info access classes utilize , want design in generic way.

what i'm after way inquire dao converter mill want dao converter can handle specific type of model item far can't find way specify this.

public abstract class abstractdataaccess<t> t: modelitem { protected idaoconverter<t,?> converter; public void init(idaoconverter<t,?> inconverter) { converter = inconverter; } }

i want able replace question marks whatever type want within class. i'm having write each info access class out due this.

if converter given @ initialization, create methods accessing daoconverter abstract, , derive (possibly abstract) class has sec type parameter representing dao-type.

public abstract class abstractdataaccess<t, tdao> : abstractdataaccess<t> ...

c# templates generics

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -