Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created July 2, 2014 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tluyben/67d78152ee092fe60794 to your computer and use it in GitHub Desktop.
Save tluyben/67d78152ee092fe60794 to your computer and use it in GitHub Desktop.
public class LastReturned {
Dictionary<Thread, object> Returned = new Dictionary<Thread, object>();
public object Ret(object o) {
if (o != null) {
if (Returned.ContainsKey (Thread.CurrentThread)) {
Returned [Thread.CurrentThread] = o;
} else {
Returned.Add (Thread.CurrentThread, o);
}
} else {
Returned.Remove (Thread.CurrentThread);
}
return o;
}
public bool RetBool(bool b) {
Ret (b);
return b;
}
public int RetInt(int b) {
Ret (b);
return b;
}
public string RetString(string b) {
Ret (b);
return b;
}
public object Ret() {
return Returned.ContainsKey (Thread.CurrentThread) ? Returned[Thread.CurrentThread] : null;
}
public bool RetBool() {
var o = Ret ();
return o != null && o is bool ? (bool)o : default(bool);
}
public int RetInt() {
var o = Ret ();
return o != null &&o is int ? (int)o : default(int);
}
public string RetString() {
var o = Ret ();
return o != null &&o is string ? (string)o : default(string);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment