How to convert class with generic type to class with object as generic type in C# -


hello i'm using visual studio 2005 (because need compact framework support) , problem generics.

i have created abstract class called abstractdao base

from creating other classes documentdao,headerdao etc represent different tables on database

what wish retrieve number of above mentioned dao classes, abstractdao (the abstract class has number of concrete implementations wish use)

what tried

abstractdao<object> dao = new documentdao(); abstractdao<object> dao = (abstractdao<object>)new documentdao(); abstractdao<t> dao = new documentdao(); 

i need above because have created function transfers data 1 table similar table in different database, (if worked) go this

abstractdao<object> dao_local = new documentdao(local_database); abstractdao<object> dao_remote = new documentdao(remote_database);       do_transfer(dao_local,dao_remote)  void do_transfer(abstractdao<object> from, abstractdao<object> to) {      list<object> items = from.get_all();      to.insert(items); } 

is there way above?

that work if class hierachy this:

class documentdao : abstractdao<object> {     //... } 

by comment seems have type hierarchy this:

class documentdao : abstractdao<sometype> {     public override sometype foo() {         //...         return somevalue;     }     //... } class abstractdao<t> {     public abstract t foo();     //... } 

you want refactor abstractdao implement non generic interface iabstractdao:

class iabstractdao {     object foo();     //... }  class abstractdao<t> {     public object foo() {         return foo();     }     public abstract t foo();     //... } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -