This snippet offers an extension method for fluent "is between" comparison for integers. You can simply replace integer by any other numeric type, making it generic would make it not being a snippet anymore.
An example to use this extension method:
int x = 3;
if(x.IsBetween(0).And(5))
'x is between 0 and 5!
Imports System.Runtime.CompilerServices
Public Module ComparisonExtensions
''' <summary>Call .And() on the result!</summary>
<Extension()> _
Public Function IsBetween(value As Integer, minimum As Integer) As AndHelper
Return New AndHelper() With { _
.[And] = Function(maximum) (value > minimum) AndAlso (value < maximum)}
End Function
End Module
Public NotInheritable Class AndHelper
Public [And] As Func(Of Integer, Boolean)
End Class
6 Kommentare zum Snippet