So I'm guessing you are needing to pass a reference a bool, that you cannot wrap with a 'BoolWrapper' class, because the bool lives some place that you cannot or do not wish to modify.
It can be done!
First declare what any bool reference will look like
/// <summary> A reference to a bool.</summary>
/// <param name="value">new value</param>
/// <returns>Value of boolean</returns>
public delegate bool BoolRef(bool? value = null);
Now you can make a reference to myBool like this
bool myBool; // A given bool that you cannot wrap or change
private bool myBoolRef(bool? value) {
if (value != null) {
myBool = (bool)value;
}
return myBool;
}
And use it like this:
void myTestCaller() {
foo(myBoolRef);
}
void foo(BoolRef b) {
bool c = b(); // get myBool
b(true); // set myBool to true
}
The same trick works for other value types such as int