There is a generic class XXValue like this, where the Type T can be value type or reference type, e.g int, string, struct object
public class XXValue<T>
{
public T DefaultValue;
}
And there is another generic class XXAttribute
public class XXAttribute<T>
{
public T Value;
}
But the type T for XXAttribute should be the class or sub-class of type XXValue, so how to write the where statement for XXAttribute? Which one is correct?
public class XXAttribute<T> where T : XXValue<T>
public class XXAttribute<VT, AT> where AT : XXValue<VT>
Given this statement, it should be the second one.
This specifies that the type parameter for
XXAttributeshould inherit fromXXValue. But sinceXXValueis also a generic type, you need to specify its type parameter inXXAtributealso, asTBase, and pass it along.Alternatively (it’s hard to tell given the scope of the question, but you could possibly) change how
Valueis defined: