Description
The WithFlag
method is a static extension method provided by the SandboxSystemExtensions
class. It allows you to modify a value by setting or clearing a specific flag, based on a boolean condition. This method is generic and can be used with any type that supports bitwise operations.
Usage
To use the WithFlag
method, you need to pass the following parameters:
value
: The original value that you want to modify.
flag
: The flag that you want to set or clear.
set
: A boolean value indicating whether to set (true
) or clear (false
) the flag.
The method returns the modified value with the flag set or cleared as specified.
Example
// Example usage of the WithFlag method
int originalValue = 0b_0000_0101; // Binary representation: 5
int flag = 0b_0000_0010; // Binary representation: 2
// Set the flag
int newValue = originalValue.WithFlag(flag, true);
// newValue is now 0b_0000_0111 (7)
// Clear the flag
newValue = originalValue.WithFlag(flag, false);
// newValue is now 0b_0000_0101 (5)