I've toyed a bit with this issue because I like to keep the .NET DateTime as they are on the script side but the comparison operators are a bit of a trap when we write our business rules.
I wonder if javascript's valueOf is not a good solution.
The problem is to attach the valueOf method to the .NET DateTime objetcs, as expected I can't "monkey patch" the object, and it would not be convenient to have to do it that way, but if it was possible to globally define the javascript "prototype" for a .NET class (or struct), we could just set it as { valueOf: function() { return this.Ticks } } for DateTime and the operators would work (similar for TimeSpan).
The API could be something nice (another overload to provide the complete prototype could also be available):
I wonder if javascript's valueOf is not a good solution.
The problem is to attach the valueOf method to the .NET DateTime objetcs, as expected I can't "monkey patch" the object, and it would not be convenient to have to do it that way, but if it was possible to globally define the javascript "prototype" for a .NET class (or struct), we could just set it as { valueOf: function() { return this.Ticks } } for DateTime and the operators would work (similar for TimeSpan).
The API could be something nice (another overload to provide the complete prototype could also be available):
engine.AddHostType<DateTime>(valueOf: (instance) => instance.Ticks);