I have two generic classes: A and B. From B I have to create instances of A. But the main problem is I don't know how to pass information about collection items type to type parameters list in A constructor: new A</*What must be written here?*/>()
.
// There we must know what T type parameter represents.
public class A<TItem>
{
public void Method(IEnumerable<TItem> sequence)
{
}
}
// TObject can be everyone type. It is not contrained.
public class B<TObject>
{
public void Method(TObject obj)
{
// Assume that we ensured that obj is IEnumerable<>, but how to create instance of A?
// May be there is another way to solve this problem...
}
}
Aucun commentaire:
Enregistrer un commentaire