public object FireEvent(string name, object[] objects) { return(RemoteDelegates.ContainsKey(name) ? RemoteDelegates[name].FastDynamicInvoke(objects) : null); //if (!RemoteDelegates.ContainsKey(name)) return null; //object result = null; //foreach (var d in RemoteDelegates[name]) //{ // result = d.FastDynamicInvoke(objects); //} //return result; }
/// <summary> /// Tries the set member. /// </summary> /// <param name="binder">The binder.</param> /// <param name="value">The value.</param> /// <returns></returns> public override bool TrySetMember(SetMemberBinder binder, object value) { if (base.TrySetMember(binder, value)) { if (value is AddRemoveMarker m) { if (m.IsAdding) { if (m.Delegate is Delegate md) { value = md; } else if (m.Delegate is Expression exp) { value = exp.GetContract(binder.Name); } else { value = null; return(false); } } else // -= { if (m.Delegate is Delegate md) { var contract = new EventContract(binder.Name, md.Method.Name, false); RemoteDelegates.Remove(contract.Description); value = contract; } else if (m.Delegate is Expression exp) { var contract = exp.GetContract(binder.Name); contract.IsAdd = false; value = contract; } else { value = null; } } } if (value is Delegate d) { var contract = new EventContract(binder.Name, d.Method.Name, true); RemoteDelegates[contract.Description] = d; value = contract; } Agent.Execute(new RemoteInvocation(InvocationKind.Set, binder.Name, value)); return(true); } return(false); }