public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var msg = new Message(binder, args); Apply(msg); result = null; return true; }
public virtual void Apply(Message msg) { var instances = Registry.InstancesForMessage(msg).ToArray(); foreach (var inst in instances.Where(x=> x is AR)) (inst as AR).Apply = this; foreach (var inst in instances) msg.InvokeOnInstanceIfPossible(inst, "Can"); foreach (var inst in instances) msg.InvokeOnInstanceIfPossible(inst); }
// this would intercept all messages before 2012/01/16 20:45 public IEnumerable<Message> InterceptMessagesBefore_2012_01_16_20_45(Message msg) { switch (msg.MethodName) { case "SomeMessage": // meters to kilometers means divide old msgs length by 1000 yield return new Message(msg.MethodName,msg.Parameters.Substitute("Length",x=>x.Value/1000)); break; case "AnotherMessage": yield return new Message("AnotherBlah",msg.Parameters.Where(x=>x.Key == "TargetId")); yield return new Message("AnotherBlah2",msg.Parameters.Where(x=>x.Key !="TargetId")); break; default: yield return msg; break; } }
// this would intercept all "Foo" messages before 2011/12/12 00:00 public IEnumerable<Message> InterceptFooMessagesBefore_2011_12_12_00_00(Message msg) { yield return new Message("Bar", msg.Parameters); }