ValidationRules MinValue Workaround?ValidationRules MinValue Workaround?
Old forum URL: forums.lhotka.net/forums/t/1315.aspx
brembot posted on Sunday, September 24, 2006
Does anyone implemented this? There's a bug in implementing ValidationRules to a Short datatype.
ValidationRules.AddRule(AddressOf CommonRules.MinValue(Of Short), New CommonRules.MinValueRuleArgs(Of Short)("MyProperty", 1))
Validation Rules does not work if the value is -1 (negative 1) but if the value is 0 (zero) it works.
Thanks
RockfordLhotka replied on Sunday, September 24, 2006
The only workaround is to either apply the change to MinValue that I implemented in version 2.1, or to write your own version of MinValue for your application and use that instead.
As we discussed in another thread, the issue is a bug in the Int16 (Short) data type, where its CompareTo implementation returns arbitrary negative values rather than -1 like it is supposed to.
brembot replied on Sunday, September 24, 2006
Thank you very much Rocky. I applied the changes and it works as expected. That's solved my problem co'z i don't want to break our coding standards.
ajj3085 replied on Monday, September 25, 2006
RockfordLhotka: As we discussed in another thread, the issue is a bug in the Int16 (Short) data type, where its CompareTo implementation returns arbitrary negative values rather than -1 like it is supposed to.
Rocky, do you have any code to repo this? I haven't run into this problem in C#, which is not what I would expect.
RockfordLhotka replied on Monday, September 25, 2006
Hmm. I actually traced it down in C# first, because the
first person who discovered it was a C# user.
I simply wrote an editable child class with a single short
property (using the C# data type, not Int16), put them in an editable root
collection. Added a MinValue rule for that short property and bound it to a
WinForm grid. Immediate failure.
Walk through in the debugger and you find that the short
data type returns values other than -1 - and my code in MinValue (and MaxValue)
check specifically for -1, 0 or 1. Now they are more forgiving - checking for
<0, 0, >0.
Rocky
RockfordLhotka:
As we discussed in another thread, the issue is a bug in the Int16
(Short) data type, where its CompareTo implementation returns arbitrary
negative values rather than -1 like it is supposed
to.
Rocky, do you have any code to repo this?
I haven't run into this problem in C#, which is not what I would
expect.
ajj3085 replied on Monday, September 25, 2006
Ok, that's what i would expect. I wrote a small test program that only did CompareTo on shorts, but I must have not written it properly.
Copyright (c) Marimer LLC