Error in DateTime? type.
toolgood opened this issue · 4 comments
var jsEngine = new MsieJsEngine(new JsEngineSettings {
EngineMode = JsEngineMode.Auto,
UseEcmaScript5Polyfill = false,
UseJson2Library = false
});
DateTime? n = DateTime.Now;
jsEngine.EmbedHostObject("n", n);
jsEngine.Execute(@"n.Value.ToString(""yyyy-MM-dd"")");
MsieJavaScriptEngine.JsRuntimeException:“TypeError: Unable to get property 'ToString' of undefined or null reference
at Global code (Script Document:1:1)”
Hello!
EmbedHostObject
method allows to embed instances of simple classes (or structures) and delegates. Unfortunately, generic and nullable types do not belong to simple classes and structures. You can use a DateTime
instead of a DateTime?
.
Don't forget to wrap your code in a using
block.
Thank you.
public class DateTimeNull
{
private DateTime? datetime;
public bool HasValue { get { return datetime != null ? datetime.HasValue : false; } }
public DateTime Value { get { return datetime.Value; } }
public static implicit operator DateTimeNull(DateTime value)
{
DateTimeNull date = new DateTimeNull();
date.datetime = value;
return date;
}
public static implicit operator DateTimeNull(DateTime? value)
{
DateTimeNull date = new DateTimeNull();
date.datetime = value;
return date;
}
}
DateTimeNull
instead of DateTime
, test passed.
In future, I will try to solve this problem. I just now have other priorities. I try to spend all my free time on development of third versions of the MSIE JavaScript Engine and the JavaScript Engine Switcher. Because of this, even had to suspend development of the WebMarkupMin.