I want to do something like this. But I can’t use IMyInterface as the generic type for MyField because it is not promised to be managed. Is there any work around?
public struct Main<T> where T: unmanaged
{
MyField<IMyInterface<T>> value;
public Main( Flag flag)
{
switch (flag)
{
case Flag.A:
value = new MyField<A<T>>();
break;
...
}
}
}
public struct MyField<T> where T: unmanaged { }
public struct A<T> : IMyInterface<T> where T: unmanaged {...}
public struct B<T> : IMyInterface<T> where T: unmanaged {...}
public struct C<T> : IMyInterface<T> where T: unmanaged {...}
public struct D<T> : IMyInterface<T> where T: unmanaged {...}
public interface IMyInterface<T> where T: unmanaged
{
//Some members.
}
New contributor
Zhanhong Li is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.