This project is read-only.
1
Vote

VB program can't get right value from property

description

Hi, thank you for your great work!

I found that VB program can't get correct value via DynamicJson.Parse.
'reproduction code
Dim o as Object = DynamicJson.Parse("{""strprop"":""abc"", ""numprop"": 123}")
Console.WriteLine("strprop:" & o.strprop)        '=> True
Console.WriteLine("numprop:" & o.numprop)  '=> True
I suppose that it was caused by VB specification. It initially calls 'TryInvokeMember' by design. Because VB does not require to add () for method calling. And DynamicJson returned true, then it use wrong value.

The below is my fix for VB
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            if (args.Length > 0)
            {
                result = null;
                return false;
            }

            if (IsDefined(binder.Name))
            {
                TryGet(xml.Element(binder.Name), out result);
                return true;
            }
            result = null;
            return false;
        }
Regards

comments