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

New Post: Problem with nullable property of object

$
0
0
Hi,

Small bug with the new MarshalNullAsDispatch option.
String property in case of null value should always return the DBNull value instead of DispatchWrapper(null).
Following code does not work :
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ClearScript.Windows;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var scriptEngine = new VBScriptEngine(WindowsScriptEngineFlags.MarshalNullAsDispatch))
            {
                var script = @"
                    function getName
                    getName = person.Name
                    end function
                ";
                scriptEngine.Execute(script);
                scriptEngine.Script.person = new Person();
                Console.WriteLine("Person name is '{0}'", scriptEngine.Script.getName());
                Console.ReadKey();
            }
        }
    }

    public class Person
    {
        public string Name { get; set; } 
    }
}
Without MarshalNullAsDispatch option the getName() function return Undefined object. Is it behavior by design?
Is it not should return to .NET the null value?

Thanks

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images