Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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