Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
2 different base classes or 1 class or something else?
Message
De
18/01/2015 04:42:52
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01613723
Message ID:
01613804
Vues:
21
>>>>Not absolutely sure I understand your requirements but something like ? :
public class RepositoryBase<T> where T:class
>>>>    {
>>>>        private List<T> _list;
>>>>        protected RepositoryBase(List<T> x )
>>>>        {
>>>>            _list = x;
>>>>        }
>>>>    }
>>>>
>>>>    public class GuestBase<T,TList> : RepositoryBase<T> where T:class where TList:class
>>>>    {
>>>>        protected GuestBase(List<T> thing) : base(thing)
>>>>        {}
>>>>    }
>>>>
>>>>    public class GuestRepository : GuestBase<X,Guests>
>>>>    {
>>>>        private List<Guests> _guests; 
>>>>        public GuestRepository(List<X> xx, List<Guests> guests ) : base(xx)
>>>>        {
>>>>            _guests = guests;
>>>>        }
>>>>    }
>>>
>>>I'll see if I can go from here. What about the interface? Our current baseRepository is also using the interface, e.g.
>>>
>>> public abstract class RepositoryBase<T> : IRepository<T> where T : class
>>>
>>>What should I do with this?
>>
>>I guess you could use composition (though there may be something better):
public interface IGuestBase<TList> where TList:class
>>    {
>>        
>>    }
>>
>>// then
>> public class GuestRepository : GuestBase<X,Guests>,IGuestBase<Guests>
>>    {
>>     }
BTW GuestBase is probably not a good name for that class since it is still generic
>
>I got a solution here https://social.msdn.microsoft.com/Forums/en-US/a966a12d-a3c4-40bb-8db8-58ac974b4a52/new-class-using-generics?forum=csharpgeneral
>
>So, the solution was to have base of two classes and then have my other base based on that.

Hmm. That class structure looks 'upside-down' to me - the extended version is in the base class and your existing (simpler) implementation becomes a sub class which seems pointless - as is the IRepositoryBase interface which isn't (and in fact couldn't) be used.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform