Why assume Photoshop?Restricts implicit data type conversions to only widening conversions, disallows late binding, and disallows implicit typing that results in an Object type.
Where does it state that the "comparison" operators must return Boolean? Is possible they can return something else?
Try it out. Doesn't take two minutes to discover, that this assumption is incorrect.
So if operators are defined by the type that implements them.Code:Public Class Eg Shared Operator < (ByVal a As Integer, b As Integer) As Eg End Operator End Class
And the a comparison operators aren't activated via IComparable(Of T) interface cos interfaces can't implement static / shared methods.
So you could (and can) define an object (or as in my implementation multiple objects) that lifts the value into a different type where you can implement operators that does bounds checking.
Seeing that you don't believe me here that is possible. Here is the code, that does it.
I use the extension method .__ (I would use ._ but that's not a valid identifier for a method), that does the initial lifting of the type. Since it less visually intrusive than then the implicit conversion operator.Code:Public Class PartA(Of T As IComparable(Of T)) Private _Value As T Public Sub New(Value As T) _Value = Value End Sub Public ReadOnly Property Value As T Get Return _Value End Get End Property Public Shared Widening Operator CType(ByVal Value As T) As PartA(OF T) Return New PartA(Of T)(Value) End Operator Public Shared Operator <(ByVal P As PartA(of T) , Value As T) As PartB(OF T) Return New PartB(Of T)( P.Value.CompareTo(Value)<0, Value) End Operator Public Shared Operator <=(ByVal P As PartA(of T) , Value As T) As PartB(OF T) Return New PartB(Of T)( P.Value.CompareTo(Value)<=0, Value) End Operator <Obsolete("Not Used",True)> Public Shared Operator >(ByVal P As PartA(of T) , Value As T) As PartB(OF T) Throw New NotImplementedException() End Operator <Obsolete("Not Used",True)> Public Shared Operator >=(ByVal P As PartA(of T) , Value As T) As PartB(OF T) Throw New NotImplementedException() End Operator End Class Public Class PartB(Of T As IComparable(Of T)) Private _CMP As Boolean Private _Value As T Public Sub New(CmpState As Boolean, Value As T) _CMP =CmpState _Value = Value End Sub Public ReadOnly Property Value As T Get Return _Value End Get End Property Public ReadOnly Property State As Boolean Get Return _CMP End Get End Property Public Shared Operator <(ByVal P As PartB(of T) , Value As T) As Boolean Return P.State AndAlso ( P.Value.CompareTo(Value)<0) End Operator Public Shared Operator <=(ByVal P As PartB(of T) , Value As T) As Boolean Return P.State AndAlso ( P.Value.CompareTo(Value)<=0) End Operator <Obsolete("Not Used",True)> Public Shared Operator >(ByVal P As PartB(of T) , Value As T) As Boolean Throw New NotImplementedException() End Operator <Obsolete("Not Used",True)> Public Shared Operator >=(ByVal P As PartB(of T) , Value As T) As Boolean Throw New NotImplementedException() End Operator End Class
Took about 15-20 minute to implement as well.Code:Public Module Exts <Runtime.CompilerServices.Extension> Public Function __(Of T As IComparable(Of T))(Value As T) As PartA(Of T) Return New PartA(Of T)(Value) End Function End Module
I await the apologies.![]()




Reply With Quote
