/// <summary> /// Get a global variable value from the JavaScript context /// </summary> /// <param name="name">The variable name</param> /// <param name="result">The output value</param> /// <returns></returns> private bool GetMember(string name, out object result) { if (name.EndsWith("()")) { var script = "{0}".format(name); result = this.Run(script); } else { result = _javaScriptContextImplementation.GetParameter(name); } if (_javaScriptContextImplementation.IsJavaScriptDate(result)) { result = _javaScriptContextImplementation.JavaScriptDateToNETDateTime(result); } // If the value returned is a IDictionary<string, object> AKA a JavaScript // object we return it as a JavaScriptInstance so we can handle the dynamic // aspect of it in C# else if (_javaScriptContextImplementation.IsJavaScriptObject(result)) { var dic = _javaScriptContextImplementation.JavaScriptObjectToNETDictionary(result); dynamic d = new DynamicJavaScriptInstance(dic); result = d; } else // Convert some value type into .net value type. Jurassic support string and concatenated string // which we need to convert into string on the fly. this is why we have this call { result = _javaScriptContextImplementation.JavaScriptValueTypeToNETValueType(result); } return(true); }
/// <summary> /// Get the value of a property using the property syntax /// </summary> /// <param name="binder"></param> /// <param name="result"></param> /// <returns></returns> public override bool TryGetMember(GetMemberBinder binder, out object result) { if (!_dic.ContainsKey(binder.Name)) { throw new ApplicationException(String.Format("property '{0}' not defined in object", binder.Name)); } result = _dic[binder.Name]; if (___globalJavaScriptContext.IsJavaScriptDate(result)) { result = ___globalJavaScriptContext.JavaScriptDateToNETDateTime(result); } // If we have to return an array we replace all the element of the array that // are an object by our wrapper JavaScriptInstance around the object. // So we can continue to get the C# dynamic syntax if (___globalJavaScriptContext.IsJavaScriptArray(result)) { result = MakeDynamicObjectArray( ___globalJavaScriptContext.JavaScriptArrayToNETArray(result) ); } // If the value returned a JavaScript object we return it as a // JavaScriptInstance so we can handle the dynamic aspect of it in C# else if (___globalJavaScriptContext.IsJavaScriptObject(result)) { var dic = ___globalJavaScriptContext.JavaScriptObjectToNETDictionary(result); dynamic d = new DynamicJavaScriptInstance(dic); result = d; } else { result = ___globalJavaScriptContext.JavaScriptValueTypeToNETValueType(result); } return(true); }