-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-Language DesignFeature RequestLanguage-VBResolution-DuplicateThe described behavior is tracked in another issueThe described behavior is tracked in another issue
Description
Overload resolution should bind to the overload that is most specific including generic type parameters (constrained or not)
Sub Foo(Of T As Struct)( Bar As T) // 0
Sub Foo(Of T As Class)( Bar As T) // 1
If Foo is called with an integer, then method 0 is used.
If Foo is called with a string, then method 1 is used.
This would allow the methods to me specialised for that type of object. For example the difference is the null checks in the case of a class type.
Public Function IsBetween(Of T As {class, IComparable(Of T) } )
( value As T,
lower as T,
upper as T
) As Boolean
If value Is Nothing Then Throw New NullArgumentException()
If lower Is Nothing Then Throw New NullArgumentException()
If upper Is Nothing Then Throw New NullArgumentException()
Return _IsBetween(Of T)( value, lower, upper )
End Function
Public Function IsBetween(Of T As {class, IComparable(Of T) } )
( value As T,
lower as T,
upper as T
) As Boolean
Return _IsBetween(Of T)( value, lower, upper)
End Function
Private Function _IsBetween(Of T As IComparable(Of T))
( value As T,
lower As T,
upper As T
) As Boolean
Return (lower.ComparedTo(value) <= 0) AndAlso
(value.ComparedTo(upper) <= 0)
End Function
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-Language DesignFeature RequestLanguage-VBResolution-DuplicateThe described behavior is tracked in another issueThe described behavior is tracked in another issue