public static JSBool CoerceToBool(IJSObject a) { bool outcome; switch (a.Type) { case JSType.String: outcome = ((JSString)a).Value == ""; break; case JSType.Boolean: outcome = ((JSBool)a).Value; break; case JSType.Number: outcome = ((JSNumber)a).Value == 0; break; case JSType.Null: outcome = false; break; case JSType.Undefined: outcome = false; break; default: outcome = true; break; } return(new JSBool(outcome)); }
public virtual void TrackObject(IJSObject obj) { this.jsCtx.ExecuteScriptFunction("CommonAPI.TrackObject", new object[] { this.jsCtx.EscapeJSObject(obj) }); }
public IEnumerator <T> GetEnumerator() { if (typeof(IJSObject).IsAssignableFrom(typeof(T))) { for (int i = 0; i < this.Count; i++) { object value = Interop.ExecuteJavaScript("$0[$1]", this.UnderlyingJSInstance, i); IJSObject o = (IJSObject)(object)Activator.CreateInstance <T>(); o.UnderlyingJSInstance = value; yield return((T)(object)o); } } else //else if (JSObject.Helper_IsBuiltInType<T>()) { for (int i = 0; i < this.Count; i++) { object value = Interop.ExecuteJavaScript("$0[$1]", this.UnderlyingJSInstance, i); yield return(JSObject.Helper_ConvertTo <T>(value)); } } // ---------------- // Disabled this portion of code because it doesn't work well once translated into js, // instead the value is directly cast and return, will throw anyway if it's not compatible // ---------------- //else // throw new Exception("The generic type parameter '" + typeof(T).Name + "' is not a built-in type or a JSObject."); }
// -= COMPARISON =- // TODO: Alg. isn't absolutely perfect public static JSBool StrictlyEqual(IJSObject a, IJSObject b) { if (a.Type != b.Type) { return(new JSBool(false)); } return(Equal(a, b)); }
public T this[int index] { get { if (index < 0 || index >= this.Count) { throw new ArgumentOutOfRangeException(); } object value = Interop.ExecuteJavaScript("$0[$1]", this.UnderlyingJSInstance, index); if (typeof(IJSObject).IsAssignableFrom(typeof(T))) { IJSObject o = (IJSObject)(object)Activator.CreateInstance <T>(); o.UnderlyingJSInstance = value; return((T)(object)o); } else { return((T)value); } // ---------------- // Disabled this portion of code because it doesn't work well once translated into js, // instead the value is directly cast and return, will throw anyway if it's not compatible // ---------------- // //else if (JSObject.Helper_IsBuiltInType<T>()) // return JSObject.Helper_ConvertTo<T>(value); //else // throw new Exception("The generic type parameter '" + typeof(T).Name + "' is not a built-in type or a JSObject."); } set { if (index < 0 || index >= this.Count) { throw new ArgumentOutOfRangeException(); } object _value; if (typeof(IJSObject).IsAssignableFrom(typeof(T))) { _value = ((IJSObject)(object)value).UnderlyingJSInstance; } else { _value = value; } // ---------------- // Disabled this portion of code because it doesn't work well once translated into js, // instead the value is directly cast and return, will throw anyway if it's not compatible // ---------------- //else if (JSObject.Helper_IsBuiltInType<T>()) // _value = value; //else // throw new Exception("The generic type parameter '" + typeof(T).Name + "' is not a built-in type or a JSObject."); Interop.ExecuteJavaScriptAsync("$0[$1] = $2", this.UnderlyingJSInstance, index, _value); } }
public virtual void NotifyPropertyChanged(string trackCode, string propName, IJSObject propValue) { this.jsCtx.ExecuteScriptFunction("CommonAPI.NotifyPropertyChanged", new object[] { this.jsCtx.EscapeString(trackCode), this.jsCtx.EscapeString(propName), this.jsCtx.EscapeJSObject(propValue) }); }
public static string MakeJSID(this IJSObject thisObj) { Type typeFromHandle = typeof(IJSObjectHelpers); lock (typeFromHandle) { IJSObjectHelpers.lastJsId += 1UL; } return(thisObj.GetType().Name + "-" + IJSObjectHelpers.lastJsId); }
// TIL: A _remainder_ operator is not quite a _modulo_ operator public static IJSObject Remainder(IJSObject a, IJSObject b) { if (a.Type == JSType.Number && b.Type == JSType.Number) { var aN = (JSNumber)a; var bN = (JSNumber)b; return(new JSNumber(aN.Value % bN.Value)); } else { return(new JSNaN()); } }
public string EscapeJSObjectValue(object o) { IJSObject ijsobject = o as IJSObject; if (ijsobject != null) { return(this.EscapeJSObject(ijsobject)); } IEnumerable <IJSObject> enumerable = o as IEnumerable <IJSObject>; if (enumerable != null) { return(this.EscapeArray(enumerable)); } return(JavascriptSerializer.SerializeJavascriptObject(o)); }
// -= ARITHMETIC =- public static IJSObject Plus(IJSObject a, IJSObject b) { if (a.Type == JSType.Number && b.Type == JSType.Number) { var aN = (JSNumber)a; var bN = (JSNumber)b; return(new JSNumber(aN.Value + bN.Value)); } else if (a.Type == JSType.String || b.Type == JSType.String) { return(new JSString($"{a.AsCSharpString}{b.AsCSharpString}")); } else { throw new NotImplementedException("Addition of those two types is not implemented"); } }
public string EscapeJSObject(IJSObject o) { ITrackableJSObject trackableJSObject = o as ITrackableJSObject; if (trackableJSObject != null) { if (trackableJSObject.IsTracked) { return("CommonAPI.GetTrackedObject(" + JavascriptSerializer.Serialize(trackableJSObject.TrackingCode) + ")"); } if (trackableJSObject.ConstructorFunction != null) { return(this.CallJSConstructor(trackableJSObject)); } } return(JavascriptSerializer.Serialize(o.ToJavascriptObject())); }
// TODO: Implement this properly with type conversion // For now we'll only support getting here through StrictEquality public static JSBool Equal(IJSObject a, IJSObject b) { bool areEqual; switch (a.Type) { case JSType.Number: areEqual = ((JSNumber)a).Value == ((JSNumber)b).Value; break; case JSType.String: areEqual = ((JSString)a).Value == ((JSString)b).Value; break; default: throw new NotImplementedException($"Equality between type {a.Type} and {b.Type} is not implemented"); } return(new JSBool(areEqual)); }
/// <summary> /// Creates a new <see cref="JSObjectHandle"/> for the provided object. /// </summary> /// <param name="target">The object to marshal to javascript</param> /// <returns></returns> public static JSObjectHandle Create(IJSObject target) => Create(target, JSObjectMetadataProvider.Get(target.GetType()));
public void Callback(IJSObject Parent, IJSMethod Method) { if (m_Proc != null) m_Proc(Parent, Method); }
partial void Initialize(IJSObject element, EditorOptions options) { base.Initialize(); }
internal void OnOnPropertyChangeEventHandler(IJSObject Sender, IJSProperty Prop) { if (OnPropertyChange != null) { JSPropertyChangeEventArgs args = new JSPropertyChangeEventArgs(); args.Sender = Sender; args.Prop = Prop; OnPropertyChange(this, args); } }
public void Set(IJSObject Parent, IJSProperty Prop) { if (m_Proc != null) m_Proc(Parent, Prop); }
internal void OnExecuteMethodEventHandler(IJSObject Sender, IJSMethod Method) { if (OnExecuteMethod != null) { JSExecuteMethodEventArgs args = new JSExecuteMethodEventArgs(); args.Sender = Sender; args.Method = Method; OnExecuteMethod(this, args); } }
public void Dispose() { if (connectionPoint != null) { try { //connectionPoint.Unadvise(connectionCookie); } catch (Exception) { } connectionPoint = null; connectionCookie = 0; } if (m_JSObject != null) Marshal.ReleaseComObject(m_JSObject); m_JSObject = null; }
partial void Initialize(IJSObject element, TreeViewOptions options) { this.Init(); base.Initialize(); }
public virtual void NotifyElementReplaced(string trackCode, string collectionPropName, int position, IJSObject newElement) { this.jsCtx.ExecuteScriptFunction("CommonAPI.NotifyElementReplaced", new object[] { this.jsCtx.EscapeString(trackCode), this.jsCtx.EscapeString(collectionPropName), position, this.jsCtx.EscapeJSObject(newElement) }); }
public static object ToJavaScriptObject(this IJSObject o) { return(o.UnderlyingJSInstance); }
/// <summary> /// Creates a new <see cref="JSObjectHandle"/> for the provided object by specifying the <see cref="IJSObjectMetadata"/> of the target. /// </summary> /// <param name="target">The object to marshal to javascript</param> /// <param name="metadata">Metadat of the <paramref name="target"/>.</param> /// <returns></returns> public static JSObjectHandle Create(IJSObject target, IJSObjectMetadata metadata) => new JSObjectHandle(target, metadata);
public void OnExecuteMethod(IJSObject Sender, IJSMethod Method) { m_JSObject.OnExecuteMethodEventHandler(Sender, Method); }
public static JSBool StrictlyNotEqual(IJSObject a, IJSObject b) { return(new JSBool( !StrictlyEqual(a, b).Value )); }
public void OnPropertyChange(IJSObject Sender, IJSProperty Prop) { m_JSObject.OnOnPropertyChangeEventHandler(Sender, Prop); }
public static JSBool NotEqual(IJSObject a, IJSObject b) { return(new JSBool( !Equal(a, b).Value )); }
partial void Initialize(IJSObject element, GridOptions options) { this.Init(); base.Initialize(); }