Last active
January 4, 2016 21:29
-
-
Save Buildstarted/8680904 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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