Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Date marshalling

$
0
0
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):
engine.AddHostType<DateTime>(valueOf: (instance) => instance.Ticks);

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>