Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why do generic type restrictions have to be redeclared on descendant types?
- interface IGenericType<T> where T : new()
- class GenericTypeImplementation<U> : IGenericType<U>
- class GenericTypeImplementation<U> : IGenericType<U> where U : new()
- interface IGenericType<T> where T : new()
- interface IGenericType2<T> where T : SomeOtherType
- class GenericTypeImplementation<U> : IGenericType<U>, IGenericType2<U>
- /* Hypothesis: Compiler can't infer U must be "SomeOtherType + new()" */
- Error 1 The type 'U' must have a public parameterless constructor in order to use it as parameter 'T' in the generic type or method '....IGenericType<T>'
- Error 2 The type 'U' must be convertible to '....SomeOtherType' in order to use it as parameter 'T' in the generic type or method '....IGenericType2<T>'
- class GenericTypeImplementation<U> : IGenericType<U>, IGenericType2<U>
- where U : SomeOtherType, new()
- {...}
- class GenericTypeImplementation : IGenericType<SomeType>, IGenericType2<SomeOtherType>
- {...}
- class Implementation<T> : IGenericType<List<T>> { /* ... */ }
- interface ISomething {
- void DoIt<T>() where T : new();
- }
- class OneThing : ISomething {
- public void DoIt<T>() where T : new() { }
- }
- class OtherThing : ISomething {
- void ISomething.DoIt<T>() { }
- }
Add Comment
Please, Sign In to add comment