JustIn theory you could add the extra type to the generic types for the class itself:
public class LDBList<A, T> : List<T> where T : LDBRootClass
{
// typical constructor
public LDBList(LDBList<A, T> x) : base(x) { }
public LDBList(
Func<A, T> converter,
IList<A> aList)
{
foreach (var x in aList)
{
this.Append(converter(x));
}
}
}
But of course that means that you need to declare the instances of that type with an extra type parameter that you won't even need unless you're using that specific constructor. So that's no good.
You could declare a helper class like so:
public static class LDBListCreator
{
public static LDBList<T> CreateFrom<T, A>(Func<A, T> converter, IList<A> aList) where T: LDBRootClass
{
var result = new LDBList<T>();
result.AddRange(aList.Select(converter));
return result;
}
}
This assumes that LDBList<T> has a default constructor.
But on inspection, you should be able to see that it's pointless creating such a simple helper class. If you add a constructor to your list class that accepts an IEnumerable<T> (like the List<T> class has) like so:
public LDBList(IEnumerable<T> items) : base(items)
{
}
Then you can construct an instance of LDBList<T> just by using IEnumerable.Select().
For example, given:
public class LDBRootClass
{
}
public class DerivedLDBRootClass : LDBRootClass
{
public DerivedLDBRootClass(string value)
{
// .. whatever
}
}
Then you could convert from a List<string> to a LDBList<DerivedLDBRootClass> very simply without any additional scaffolding, like so:
var strings = new List<string> { "One", "Two", "Three", "Four", "Five" };
var result = new LDBList<DerivedLDBRootClass>(strings.Select(item => new DerivedLDBRootClass(item)));