Technically, int , etc. also do not implement these operators. They are not provided by "operators" in the usual sense (which is associated with static- call ), but represented directly by the add operation code. Ultimately, the failure in this case actually comes from the Expression API:
var x = Expression.Parameter(typeof(byte)); var y = Expression.Parameter(typeof(byte)); var func = Expression.Lambda<Func<byte,byte,byte>>( Expression.Add(x,y), x, y).Compile();
To fix this, MiscUtil would have to use special versions of byte / sbyte ; sort of:
var x = Expression.Parameter(typeof(byte)); var y = Expression.Parameter(typeof(byte)); var func = Expression.Lambda<Func<byte,byte,byte>>( Expression.Convert( Expression.Add( Expression.Convert(x, typeof(int)), Expression.Convert(y, typeof(int)) ),typeof(byte)), x, y).Compile();
But! It has been a long time since I knew my keys to Jon repo, p
Oddly enough, however, itβs not so difficult to implement the whole thing in raw IL ... I actually stumbled upon (on a USB stick) a very old .NET 2.0 (ie before Expression ) version of the "generic operators", which I wrote many years ago that he could do this job. Or easier: just put the MiscUtil file locally to handle byte / sbyte .
source share