Restrict interface availability depending on parameter #551
Replies: 3 comments
-
I definitely don't want this. I'd rather have it in another type extending The question of ordering and how it relates to equality isn't addressed here either. |
Beta Was this translation helpful? Give feedback.
-
The CLR has no facility to allow conditional interfaces at all, let alone driven by a generic type argument. How would you propose such a feature be implemented in CLR metadata? |
Beta Was this translation helpful? Give feedback.
-
Related: #164 extension class ListExtensions<T> : List<T>, IEquatable<List<T>> where T : IEquatable<T> { ... }
// alternative syntax, just for the sake of readability
implement<T> IEquatable<List<T>> for List<T> where T : IEquatable<T> { .. } However, the proposal does not cover implementing regular interfaces (because it most likely requires clr support, along with "default interface methods", maybe), but I think that's definitely on the table. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Objective: Let
List<T>
implementIEquatable<List<T>>
if and only ifT
implementsIEquatable<T>
.Like in Haskell:
Beta Was this translation helpful? Give feedback.
All reactions