public object Invoke(DispatchIdentifier id, DispatchType dispType, JsValue[] jsArgs, out Type returnType) { MemberInfo member = GetMember(id.AsString); if (member == null) { returnType = typeof(void); return null; } Debug.WriteLine(string.Format("{0}, {1}.{2}", dispType, this.target, member.Name)); if (member is MethodInfo && dispType == DispatchType.PropertyGet) { var method = (MethodInfo)member; return GetMethodAsProperty((MethodInfo)member, this.target, out returnType); } var args = this.bridge.UnwrapParameters(jsArgs, dispType, member); if (dispType.IsMethod()) { var method = (MethodBase)member; returnType = method.IsConstructor ? method.DeclaringType : ((MethodInfo)method).ReturnType; return method.Invoke(this.target, args); } if (dispType.IsPropertyGet()) { var pi = (PropertyInfo)member; returnType = pi.PropertyType; return pi.GetValue(this.target, null); } if (dispType.IsPropertyPut()) { var pi = (PropertyInfo)member; pi.SetValue(this.target, args.First(), null); returnType = typeof(void); return null; } throw new NotSupportedException(); }
public object Invoke(DispatchIdentifier id, DispatchType dispType, JsValue[] args, out Type returnType) { if (id.Tag == DispatchIdentifierType.String) { if (id.AsString == "length") { return GetLength(dispType, out returnType); } else { returnType = typeof(void); return null; } } else { int intId = id.AsInt; if (intId == this.target.Length) { return GetLength(dispType, out returnType); } if (intId >= 0 && intId < this.target.Length) { Debug.WriteLine(string.Format("{0}, {1}[{2}]", dispType, this.target, id)); if (dispType == DispatchType.PropertyGet) { returnType = this.elementType; return this.target.GetValue(intId); } if (dispType == DispatchType.PropertySet) { object value = this.bridge.UnwrapValue(args.First(), this.elementType); this.target.SetValue(value, intId); returnType = typeof(void); return null; } } } throw new NotSupportedException(); }
public object Invoke(DispatchIdentifier id, DispatchType dispType, JsValue[] jsArgs, out Type returnType) { if (dispType.IsMethod()) { return InvokeMethod(dispType, id, jsArgs, out returnType); } if (dispType.IsPropertyPut()) { return SetProperty(id, jsArgs, out returnType); } if (dispType.IsPropertyGet()) { return GetProperty(id, out returnType); } throw new NotSupportedException(); }
public void OnInvokeMemberMessage(int targetId, DispatchIdentifier dispId, DispatchType dispatchType, params JsValue[] parameters) { ReadMessage(new InvokeMemberMessage { TargetId = targetId, //MemberId = memberId, DispatchId = dispId, DispatchType = dispatchType, Parameters = parameters }); }
private object SetProperty(DispatchIdentifier id, JsValue[] jsArgs, out Type returnType) { //Type targetType; //object value; //if (this.properties.TryGetValue(id.AsString, out value)) { // targetType = value.GetType(); //} //else { // this is needed so that we can make a dummy object instance var targetType = typeof(JsNativeHolder); //} var value = this.bridge.UnwrapValue(jsArgs.First(), targetType); this.SetPropertyValue(id.AsString, value); //this.bridge.SetDynamicProperty(this.target, id.AsString, value); returnType = typeof(void); return null; }
private object InvokeMethod(DispatchType dispType, DispatchIdentifier id, JsValue[] jsArgs, out Type returnType) { // if remote delegate, shouldn't be here, let client side handle that case // overridden methods might exist in the properties map, // otherwise try and invoke the method on the target MethodBase method = this.targetType.GetMethod(id.AsString); if (method == null) { object value; if (this.properties.TryGetValue(id.AsString, out value)) { var del = value as Delegate; if (del != null) { var args = this.bridge.UnwrapParameters(jsArgs, dispType, del.Method); del.DynamicInvoke(args); } } returnType = typeof(void); return null; } else { var args = this.bridge.UnwrapParameters(jsArgs, dispType, method); returnType = method.IsConstructor ? method.DeclaringType : ((MethodInfo)method).ReturnType; return method.Invoke(this.target, args); } }
private object GetProperty(DispatchIdentifier id, out Type returnType) { object value; if (!this.properties.TryGetValue(id.AsString, out value)) { var method = this.targetType.GetMethod(id.AsString); if (method != null) { return GetMethodAsProperty((MethodInfo)method, this.target, out returnType); } value = null; returnType = typeof(void); } else { returnType = value.GetType(); } return value; }