c# - Collection Inheritance -


i trying achieve following, not sure if possible.

i have following 'base' entities

public abstract class baseobject {} public abstract class basecollection <t> : observablecollection<t> t : baseobject {} 

i have

public class obj_1: baseobject {} public class obj_1_collection : basecollection <obj_1> {     public obj_1_method_1 () {} } 

and

public class obj_2: obj_1 {} 

following same logic obj_1, want have obj_2_collection. want collection inherit obj_1_collection in order access methods e.g. obj_2_collection.obj_1_method_1(). have in mind trying following (in pseudocode):

public class obj_2_collection : obj_1_collection<obj_2 extends obj_1> 

meaning obj_2_collection can access obj_1_collection, collection object of type obj_2

you're there, problem didn't define obj_1_collection generic.

to so, have use syntax used basecollection<t> , restrict type t obj_1

that give :

public class obj_1_collection<t> : basecollection <t> t : obj_1 {} 

concerning use of generics , inheritance, might want read in , out modifiers keyword enable covariance , contravariance.

as side note, here c# naming conventions


Comments