Skip to content

Instantly share code, notes, and snippets.

@Buildstarted
Last active January 4, 2016 21:29
Show Gist options
  • Save Buildstarted/8680904 to your computer and use it in GitHub Desktop.
Save Buildstarted/8680904 to your computer and use it in GitHub Desktop.
public class Recorder : DynamicObject
{
private readonly ConcurrentQueue<KeyValuePair<string, object[]>> _methodsToInvoke;
public Recorder()
{
this._methodsToInvoke = new ConcurrentQueue<KeyValuePair<string, object[]>>();
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
result = null;
this._methodsToInvoke.Enqueue(new KeyValuePair<string, object[]>(binder.Name, args));
return true;
}
public void Playback<T>(T item)
{
var t = typeof(T);
KeyValuePair<string, object[]> method;
while (this._methodsToInvoke.TryDequeue(out method))
{
t.GetMethod(method.Key).Invoke(item, method.Value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment