Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Problem with nullable property of object

Hi ifle,

Only host members with strongly typed objects that derive from the Object class with specific reference type can return DispatchWrapper(null) in case of null.

Well, not quite, because that description applies to .NET strings :)

Host members like string, object, nullable<T> should return DBNull.

That doesn't seem completely correct either. A value type T that isn't numeric or boolean turns into an object reference on the script side, so a Nullable<T> without a value should probably be marshalled as nothing. And object is completely ambiguous; ideal null marshaling in that case depends entirely on what the script expects.

I'm not sure about DBNull, because .NET marshal a null value as VT_EMPTY and not as VT_NULL like DBNull

Here's what we've found in our testing:
  • DBNull.Value appears as null in both JScript and VBScript.
  • null appears as undefined in JScript and empty in VBScript.
  • new DispatchWrapper(null) appears as undefined in JScript and nothing in VBScript.
Note that this describes standard .NET marshaling. ClearScript adds another layer to ensure that, for example, host-side null appears as null on the script side. In any case, we agree that (at least) strings, nullable booleans, and nullable numerics should override MarshalNullAsDispatch, and we'll make that fix ASAP.

Thanks again for your input!

Viewing all articles
Browse latest Browse all 2297

Latest Images