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

Commented Issue: Properties of Nullable type [30]

0
0
Dear Sir or Madam,
I seems to having problems setting properties of type Nullable<> from within JScript.

Sample script:
```
function foo(obj, propValue)
{
// obj.Prop is declared as of type Nullable<double>
// neither double nor Nullable<double> works for propValue parameter
obj.Prop = propValue;
}

```
Please help,
Yours faithfully

MW
Comments: Hello MW! You're right; ClearScript does not support nullable types at the moment. Thanks for reporting this issue! We'll fix this problem as soon as possible. In the meantime, you could work around it by accessing nullable properties from the host rather than the script engine. Suppose your class looks like this: ``` C# public class MyObj { public int? Prop { get; set; } } ``` You could define a temporary helper class like this: ``` C# public static class MyObjHelpers { public static void SetProp(this MyObj myObj, dynamic value) { myObj.Prop = value; } public static object GetProp(this MyObj myObj) { return myObj.Prop; } } ``` Exposing the helper class allows you to do this in script code: ``` JavaScript myObj.SetProp(null); myObj.SetProp(123); var value = myObj.GetProp(); ``` Thanks again, and good luck!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images