Try this:
class AttributeUpgrade<T> where T : Attr
{
T oldOne;
T newOne;
}
And be aware that new
is a reserved keyword.
The where clause is optional but you might want to restrict the used types to Attr
Edit: I have omitted access specifiers on class and on members for the sake of clarity as I am not aware of what access level is needed.
Edit: Answer from comments:
In my words: You wish to re-use the template parameter from Attr in the declaration of AttributeUpgrade without introducing a new generic parameter to AttributeUpdate.
This cannot be done in C#.
You will either need the second template parameter or resort to the use of GetType()
on the Attr's inner type to get a System.Type
(but as you are aware of this, there is no type safety here).
C++ solves this by using typedefs in classes. The closest thing here are aliases but they cannot provide the feature you need.
See stackoverflow.com/questions/19790556/c-sharp-typedef-generics .
Indeed I think that the "best" way here would be to add another template parameter and runtime(!) assert that Attr's inner type is equal the one's in AttributeUpgrade
.