Create BaseClass and Base Entity Type


i have base class derive several other classes from.

public interface someclass : baseclass

and have repo class has generic methods save, getbyid(int), getall()

the return type of getallmethod() of baseclass i.e

public list<baseclass> getall()

i getting error saying should this

public list<someclass> getall

but thought someclass , baseclass same thing? long someclass derived baseclass use base object derived baseclass work methods??

what missing????

public interface ibaserepository { void save(); list<ibaseentity> getall(); ibaseentity getbyid(int id); } public interface ibaseentity { } public class planrepository : iplanrespository { public void save() { throw new notimplementedexception(); } public list<plan> getall() { throw new notimplementedexception(); } public plan getbyid(int id) { throw new notimplementedexception(); } }

    public interface iplan : ibaseentity     {         int       planid                { get; set; }      }

i errors these errors?

error 1  does not implement interface member .core.interfaces.ibaserepository.getbyid(int)'. core.repositories.planrepository.getbyid(int)' cannot implement core.interfaces.ibaserepository.getbyid(int)' because not have matching return 


developer


i think case using generics.  the example below compiles , avoids issues.

public interface ibaserepository<t>     {         void save();         list<t> getall();         t getbyid(int id);      }      public interface ibaseentity { }      public interface iplanrespository<t> : ibaserepository<t> { }      public class plan : ibaseentity { }      public class planrepository : iplanrespository<plan>     {         public void save()         {             throw new notimplementedexception();         }          public list<plan> getall()         {             throw new notimplementedexception();         }          public plan getbyid(int id)         {             throw new notimplementedexception();         }     }      public interface iplan : ibaseentity     {         int planid { get; set; }     }

you use interfaces generics including type implementation uses, such as:

    public static class interfacestest     {         public static void dotest()         {             ibaserepository<plan> instance = new planrepository();              plan plan = instance.getbyid(12);         }     }

matt



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user