Is it possible to change specific type ex: ConcurentBag<T>
to S
type.
I want to make generic class which loads data and reload source collection(list<T>
, ConcurrentBag<T>
, Dictionary)
This is my code:
public interface IRepositoryRelouder
{
private void ReloadData();
}
public interface IRepositoryLoader<out T> : IRepositoryRelouder
{
IEnumerable<T> LoadData();
}
public abstract class Test<T> : IRepositoryLoader<T>
{
protected ConcurrentBag<T> Source;
public abstract IEnumerable<T> LoadData();
private void void IRepositoryRelouder.Reload() =>
Source = new ConcurrentBag<T>(LoadData());
}
I would like to load and reload data in parent class and create child classes which have access to Source property. Is it passible to replace ConcurentBag to next generic parameter?
I wonder if it is possible something like this:
public abstract class Test<T,S> : IRepositoryLoader<T>
{
protected S <T> Source;
public abstract IEnumerable<T> LoadData();
private void void IRepositoryRelouder.Reload() =>
Source = new S <T>(LoadData());
}
Where S is ConcurrentBag<T> or List<T>
Update
I thought to separate the reloading mechanism into the parents' classes. I can have two reloading mechanisms: simple and complex (invokes several methods inside the reload method). The children's classes have access to the repository and factories. There are several insert, create methods that use linqu on the data source from the inherited class in the child classes. The complex mechanism contains additional fields and methods, so I did not want to duplicate the code. What would be better to do in this situation? Can I use a dictionary that also implementsIEnumerable?
IRepositoryRelouder interface is only for call Reload method for ech classes that implements this interface in configuration class.