jwaliszko / ExpressiveAnnotations

Annotation-based conditional validation library.
MIT License
351 stars 123 forks source link

Nullable byte not supported. #19

Closed StandBackBurrito closed 10 years ago

StandBackBurrito commented 10 years ago

This seems to be an issue with Linq and what types it determines are arithmetic.

For me Expression.Divide was the killer, but there may be other issues as well.

You can trace through the Expression.Divide code here: http://referencesource.microsoft.com/System.Core/a.html#e48196c57cc9f07c

It calls IsArithmetic which is here: http://referencesource.microsoft.com/System.Core/Microsoft/Scripting/Ast/TypeUtils.cs.html#d279c9ec254c1933

Byte is not listed in IsArithmetic.

A normal byte works because it is up-cast to a Double.

StandBackBurrito commented 10 years ago

I made a change to promote Nullable<int> and Nullable<byte> to Nullable<double>. This works, but I am not sure if it is the correct way to solve the issue.

https://github.com/StandBackBurrito/ExpressiveAnnotations/compare/nullable-byte-fix

jwaliszko commented 10 years ago

I think it is a good solution. Based on that, I've pushed some code to the trunk now. In addition I've made few modifications to be able to support all numeric types promotion to double (not only int and byte). Now, all underlying enum types (byte, sbyte, short, ushort, int, uint, long and ulong) are supported: https://github.com/JaroslawWaliszko/ExpressiveAnnotations/commit/4e0d312246d95f0cb5274624f4591d29d1c369de