/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other">The other.</param> /// <returns></returns> public bool Equals(RemoteInvocation other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.Kind, Kind) && Equals(other.Name, Name) && (Equals(other.Args, Args) || Enumerable.SequenceEqual(other.Args, Args))); }
/// <summary> /// Replays the recording on target. /// </summary> /// <param name="target">The target.</param> /// <param name="ins"></param> public object ReplayOn <T>(T target, RemoteInvocation ins) { return(ins.InvokeWithStoredArgs(target)); }
public object Execute(RemoteInvocation ins) { if (ins.Args != null) { for (var i = 0; i < ins.Args.Length; i++) { var arg = ins.Args[i]; if (arg is ExpressionContract expression) { if (expression.IsAdd) { dynamic exp = expression.Expression; Delegate d = exp.Compile(); LocalDelegates[expression.Description] = d; ins = new RemoteInvocation(InvocationKind.AddAssign, ins.Name, d); break; } else { if (LocalDelegates.ContainsKey(expression.Description) && LocalDelegates[expression.Description] is Delegate d) { ins = new RemoteInvocation(InvocationKind.SubtractAssign, ins.Name, d); break; } } } if (arg is EventContract eventContract) { if (eventContract.IsAdd) { //Func<string, object[], object> c = Dispatcher.AssignContract; //Func<object[], object> cc = Dynamic.Curry(c)(eventContract.Description); //LocalDelegates[eventContract.Description] = EventBinder.BindToEvent(eventContract.Event, _target, cc); //REF: https://stackoverflow.com/questions/7935306/compiling-a-lambda-expression-results-in-delegate-with-closure-argument var c = CreateProxyDelegateForEvent(_target, eventContract.Event, out var dType, out var pCount); Delegate cc = Dynamic.CoerceToDelegate(Dynamic.Curry(c, pCount)(eventContract.Description), dType); LocalDelegates[eventContract.Description] = cc; ins = new RemoteInvocation(InvocationKind.AddAssign, ins.Name, cc); break; } else { //if (LocalDelegates.ContainsKey(eventContract.Description) && LocalDelegates[eventContract.Description] is MulticastDelegate d) if (LocalDelegates.ContainsKey(eventContract.Description) && LocalDelegates[eventContract.Description] is Delegate d) { //EventBinder.UnbindFromEvent(eventContract.Event, _target, d); //LocalDelegates.Remove(eventContract.Description); ins = new RemoteInvocation(InvocationKind.SubtractAssign, ins.Name, d); LocalDelegates.Remove(eventContract.Description); break; } } //return null; } } } return(_recorder.ReplayOn(_target, ins)); }