Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
2 different base classes or 1 class or something else?
Message
De
16/01/2015 12:25:04
 
 
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:
01613749
Vues:
33
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>We have the following base repository class
>>>
>>>
>>>namespace SysManager.Repository
>>>{
>>>    public abstract class RepositoryBase<T> : IRepository<T> where T : class
>>>    {
>>>        protected readonly ISiriusSqlContext _siriusContext;
>>>
>>>        protected readonly IDbSet<T> _dbSet;
>>>        private readonly IExceptionParser _exceptionParser;
>>>
>>>        public RepositoryBase(ISiriusSqlContext context)
>>>        {
>>>            _siriusContext = context;
>>>            _dbSet = _siriusContext.Set<T>();
>>>            _exceptionParser = new ExceptionParser();
>>>            
>>>        }
>>>    etc.
>>>
>>>
>>>Now, I want to be able to optionally enhance it, e.g. I want to be able to pass an extra class but only in some cases, e.g. something like
>>>
>>>
>>>    public abstract class RepositoryBase<T, TList> : IRepository<T> where T : class, where TList: class
>>>    {
>>>        protected readonly ISiriusSqlContext _siriusContext;
>>>
>>>        protected readonly IDbSet<T> _dbSet;
>>>        private readonly IExceptionParser _exceptionParser;
>>>
>>>        public RepositoryBase(ISiriusSqlContext context)
>>>        {
>>>            _siriusContext = context;
>>>            _dbSet = _siriusContext.Set<T>();
>>>            _exceptionParser = new ExceptionParser();
>>>            
>>>        }
>>>
>>>
>>>Will I be able to do something like this and keep all my current declarations the same as this extra TList class I only want to use when supplied?
>>>
>>>What are my options here?
>>
>>Don't see where you're using (or want to use) TList in the above but there shouldn't be a problem. Are you getting one ?
>
>Not yet, as I don't understand what changes do I need to implement in the syntax. As I also said, this class as is already used in our application and I don't want to change all individual calls. My last idea was to create another class based on this one where I would introduce the second class.
>
>Can you help me a bit with the syntax assuming I'll go this route?
>
>Say, here is the current implementation of this class for GuestsRepository:
>
>
> public class GuestsRepository : RepositoryBase<Guests>, IGuestsRepository
>    {
>        public GuestsRepository(ISiriusSqlContext context) : base(context)
>        {
>
>        }
>
>
>For GuestsRepository I want to have another class (GuestsList). For most of the other classes I am OK with the current implementation.

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;
        }
    }
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform