Created
July 2, 2014 13:09
-
-
Save tluyben/67d78152ee092fe60794 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 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