You could do that if it was acceptable for ClassB to be a public inner class of ClassA. It's rather inelegant and ugly.
public class ClassA<T> where T : IDisposable
{
public ClassA(T thing)
{
ThingA = thing;
}
public T ThingA { get; set; }
public class ClassB
{
public ClassB(T thing)
{
ThingB = thing;
}
public T ThingB { get; set; }
}
}
This lets me use this (horrible) syntax:
var b = new ClassA<Stream>.ClassB(stm);
I think that your better bet is to write the two obvious unit tests that use Type.GetGenericParameterConstraints
to ensure that ClassA and ClassB are in sync.