You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generic type constraint in form of public static T Extension<T>(this T) where T : InterfaceOne, InterfaceTwo
Means that T must implement both interfaces: InterfaceOne and InterfaceTwo.
Currently, there is no way to define overloaded (extension) method with same signature, but different constraints. For example, following code is not valid: public static T Extension<T>(this T) where T : InterfaceOne public static T Extension<T>(this T) where T : InterfaceTwo
Proposal: allow for listing of type constraints, where constaint will be met if generic parameter meets any of listed types. For example, if we assume following code: public static T Extension<T>(this T) where T in InterfaceOne, InterfaceTwo
Would allow for any object implementing only InterfaceOne, only InterfaceOne or both.
Alternative syntax: public static T Extension<T>(this T) where T from InterfaceOne, InterfaceTwo
The text was updated successfully, but these errors were encountered:
Would definitely aid on defining a method on eg byte, int16, int32, int64, float, double, decimal etc all at once.
However shapes may solve this issue.
Generic type constraint in form of
public static T Extension<T>(this T) where T : InterfaceOne, InterfaceTwo
Means that T must implement both interfaces: InterfaceOne and InterfaceTwo.
Currently, there is no way to define overloaded (extension) method with same signature, but different constraints. For example, following code is not valid:
public static T Extension<T>(this T) where T : InterfaceOne
public static T Extension<T>(this T) where T : InterfaceTwo
Proposal: allow for listing of type constraints, where constaint will be met if generic parameter meets any of listed types. For example, if we assume following code:
public static T Extension<T>(this T) where T in InterfaceOne, InterfaceTwo
Would allow for any object implementing only InterfaceOne, only InterfaceOne or both.
Alternative syntax:
public static T Extension<T>(this T) where T from InterfaceOne, InterfaceTwo
The text was updated successfully, but these errors were encountered: