Skip to content

Bool Extensions

Andrzej Kebab edited this page Jan 22, 2024 · 9 revisions

UtilityLibrary.Core

This utility library provides extension methods for boolean operations, allowing you to perform various logical operations on boolean values.

And

Performs a logical AND operation on two boolean values.

// Example boolean values
bool firstCondition = true;
bool secondCondition = false;

// Using the And method to perform a logical AND operation
bool result = firstCondition.And(secondCondition);

// Displaying the result
Console.WriteLine($"Result of the logical AND operation: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (bool): The second boolean value.

Returns:

  • bool: The result of the logical AND operation.

And(Func other)

Performs a logical AND operation on the first boolean value and a function returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that returns a boolean
bool SomeFunction() => /* Some logic */;

// Using the And method to perform a logical AND operation with a function
bool result = firstCondition.And(() => SomeFunction());

// Displaying the result
Console.WriteLine($"Result of the logical AND operation with a function: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func): A function returning a boolean.

Returns:

  • bool: The result of the logical AND operation.

And(Func<T, bool> other, T value)

Performs a logical AND operation on the first boolean value and a function taking one parameter and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes one parameter and returns a boolean
bool SomeFunction(int parameter) => /* Some logic based on the parameter */;

// Example parameter value
int parameterValue = 42;

// Using the And method to perform a logical AND operation with a function taking one parameter
bool result = firstCondition.And(SomeFunction, parameterValue);

// Displaying the result
Console.WriteLine($"Result of the logical AND operation with a function taking one parameter: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T, bool>): A function taking one parameter and returning a boolean.
  • value (T): The parameter for the function.

Returns:

  • bool: The result of the logical AND operation.

And<T1, T2>(Func<T1, T2, bool> other, T1 value1, T2 value2)

Performs a logical AND operation on the first boolean value and a function taking two parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes two parameters and returns a boolean
bool SomeFunction(int param1, string param2) => /* Some logic based on the parameters */;

// Example parameter values
int param1 = 42;
string param2 = "Hello";

// Using the And method to perform a logical AND operation with a function taking two parameters
bool result = firstCondition.And(SomeFunction, param1, param2);

// Displaying the result
Console.WriteLine($"Result of the logical AND operation with a function taking two parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, bool>): A function taking two parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.

Returns:

  • bool: The result of the logical AND operation.

And<T1, T2, T3>(Func<T1, T2, T3, bool> other, T1 value1, T2 value2, T3 value3)

Performs a logical AND operation on the first boolean value and a function taking three parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes three parameters and returns a boolean
bool SomeFunction(double param1, bool param2, char param3) => /* Some logic based on the parameters */;

// Example parameter values
double param1 = 3.14;
bool param2 = true;
char param3 = 'A';

// Using the And method to perform a logical AND operation with a function taking three parameters
bool result = firstCondition.And(SomeFunction, param1, param2, param3);

// Displaying the result
Console.WriteLine($"Result of the logical AND operation with a function taking three parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, bool>): A function taking three parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.

Returns:

  • bool: The result of the logical AND operation.

And<T1, T2, T3, T4>(Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)

Performs a logical AND operation on the first boolean value and a function taking four parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes three parameters and returns a boolean
bool SomeFunction(double param1, bool param2, char param3) => /* Some logic based on the parameters */;

// Example parameter values
double param1 = 3.14;
bool param2 = true;
char param3 = 'A';

// Using the And method to perform a logical AND operation with a function taking three parameters
bool result = firstCondition.And(SomeFunction, param1, param2, param3);

// Displaying the result
Console.WriteLine($"Result of the logical AND operation with a function taking three parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, T4, bool>): A function taking four parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.

Returns:

  • bool: The result of the logical AND operation.

And<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)

Performs a logical AND operation on the first boolean value and a function taking five parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes five parameters and returns a boolean
bool SomeFunction(char param1, int param2, string param3, double param4, bool param5) => /* Some logic based on the parameters */;

// Example parameter values
char param1 = 'A';
int param2 = 42;
string param3 = "Hello";
double param4 = 3.14;
bool param5 = true;

// Using the And method to perform a logical AND operation with a function taking five parameters
bool result = firstCondition.And(SomeFunction, param1, param2, param3, param4, param5);

// Displaying the result
Console.WriteLine($"Result of the logical AND operation with a function taking five parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, T4, T5, bool>): A function taking five parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.
  • value5 (T5): The fifth parameter for the function.

Returns:

  • bool: The result of the logical AND operation.

AndNot

Performs a logical AND NOT operation on two boolean values.

// Example boolean values
bool firstCondition = true;
bool secondCondition = false;

// Using the AndNot method to perform a logical AND NOT operation
bool result = firstCondition.AndNot(secondCondition);

// Displaying the result
Console.WriteLine($"Result of the logical AND NOT operation: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (bool): The second boolean value.

Returns:

  • bool: The result of the logical AND NOT operation.

AndNot(Func other)

Performs a logical AND NOT operation on the first boolean value and a function returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that returns a boolean
bool SomeFunction() => /* Some logic */;

// Using the AndNot method to perform a logical AND NOT operation with a function
bool result = firstCondition.AndNot(() => SomeFunction());

// Displaying the result
Console.WriteLine($"Result of the logical AND NOT operation with a function: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func): A function returning a boolean.

Returns:

  • bool: The result of the logical AND NOT operation.

AndNot(Func<T, bool> other, T value)

Performs a logical AND NOT operation on the first boolean value and a function taking one parameter and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes one parameter and returns a boolean
bool SomeFunction(int parameter) => /* Some logic based on the parameter */;

// Example parameter value
int parameterValue = 42;

// Using the AndNot method to perform a logical AND NOT operation with a function taking one parameter
bool result = firstCondition.AndNot(SomeFunction, parameterValue);

// Displaying the result
Console.WriteLine($"Result of the logical AND NOT operation with a function taking one parameter: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T, bool>): A function taking one parameter and returning a boolean.
  • value (T): The parameter for the function.

Returns:

  • bool: The result of the logical AND NOT operation.

AndNot<T1, T2>(Func<T1, T2, bool> other, T1 value1, T2 value2)

Performs a logical AND NOT operation on the first boolean value and a function taking two parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes two parameters and returns a boolean
bool SomeFunction(int param1, string param2) => /* Some logic based on the parameters */;

// Example parameter values
int param1 = 42;
string param2 = "Hello";

// Using the AndNot method to perform a logical AND NOT operation with a function taking two parameters
bool result = firstCondition.AndNot(SomeFunction, param1, param2);

// Displaying the result
Console.WriteLine($"Result of the logical AND NOT operation with a function taking two parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, bool>): A function taking two parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.

Returns:

  • bool: The result of the logical AND NOT operation.

AndNot<T1, T2, T3, T4>(Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)

Performs a logical AND NOT operation on the first boolean value and a function taking four parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes four parameters and returns a boolean
bool SomeFunction(double param1, bool param2, char param3, string param4) => /* Some logic based on the parameters */;

// Example parameter values
double param1 = 3.14;
bool param2 = true;
char param3 = 'A';
string param4 = "Hello";

// Using the AndNot method to perform a logical AND NOT operation with a function taking four parameters
bool result = firstCondition.AndNot(SomeFunction, param1, param2, param3, param4);

// Displaying the result
Console.WriteLine($"Result of the logical AND NOT operation with a function taking four parameters: {result}");

Parameters:

  • boolean (bool

): The first boolean value.

  • other (Func<T1, T2, T3, T4, bool>): A function taking four parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.

Returns:

  • bool: The result of the logical AND NOT operation.

AndNot<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)

Performs a logical AND NOT operation on the first boolean value and a function taking five parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes five parameters and returns a boolean
bool SomeFunction(char param1, int param2, string param3, double param4, bool param5) => /* Some logic based on the parameters */;

// Example parameter values
char param1 = 'A';
int param2 = 42;
string param3 = "Hello";
double param4 = 3.14;
bool param5 = true;

// Using the AndNot method to perform a logical AND NOT operation with a function taking five parameters
bool result = firstCondition.AndNot(SomeFunction, param1, param2, param3, param4, param5);

// Displaying the result
Console.WriteLine($"Result of the logical AND NOT operation with a function taking five parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, T4, T5, bool>): A function taking five parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.
  • value5 (T5): The fifth parameter for the function.

Returns:

  • bool: The result of the logical AND NOT operation.

Or

Performs a logical OR operation on two boolean values.

// Example boolean values
bool firstCondition = true;
bool secondCondition = false;

// Using the Or method to perform a logical OR operation
bool result = firstCondition.Or(secondCondition);

// Displaying the result
Console.WriteLine($"Result of the logical OR operation: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (bool): The second boolean value.

Returns:

  • bool: The result of the logical OR operation.

Or(Func other)

Performs a logical OR operation on the first boolean value and a function returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that returns a boolean
bool SomeFunction() => /* Some logic */;

// Using the Or method to perform a logical OR operation with a function
bool result = firstCondition.Or(() => SomeFunction());

// Displaying the result
Console.WriteLine($"Result of the logical OR operation with a function: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func): A function returning a boolean.

Returns:

  • bool: The result of the logical OR operation.

Or(Func<T, bool> other, T value)

Performs a logical OR operation on the first boolean value and a function taking one parameter and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes one parameter and returns a boolean
bool SomeFunction(int parameter) => /* Some logic based on the parameter */;

// Example parameter value
int parameterValue = 42;

// Using the Or method to perform a logical OR operation with a function taking one parameter
bool result = firstCondition.Or(SomeFunction, parameterValue);

// Displaying the result
Console.WriteLine($"Result of the logical OR operation with a function taking one parameter: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T, bool>): A function taking one parameter and returning a boolean.
  • value (T): The parameter for the function.

Returns:

  • bool: The result of the logical OR operation.

Or<T1, T2>(Func<T1, T2, bool> other, T1 value1, T2 value2)

Performs a logical OR operation on the first boolean value and a function taking two parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes two parameters and returns a boolean
bool SomeFunction(int param1, string param2) => /* Some logic based on the parameters */;

// Example parameter values
int param1 = 42;
string param2 = "Hello";

// Using the Or method to perform a logical OR operation with a function taking two parameters
bool result = firstCondition.Or(SomeFunction, param1, param2);

// Displaying the result
Console.WriteLine($"Result of the logical OR operation with a function taking two parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, bool>): A function taking two parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.

Returns:

  • bool: The result of the logical OR operation.

Or<T1, T2, T3>(Func<T1, T2, T3, bool> other, T1 value1, T2 value2, T3 value3)

Performs a logical OR operation on the first boolean value and a function taking three parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes three parameters and returns a boolean
bool SomeFunction(double param1, bool param2, char param3) => /* Some logic based on the parameters */;

// Example parameter values
double param1 = 3.14;
bool param2 = true;
char param3 = 'A';

// Using the Or method to perform a logical OR operation with a function taking three parameters
bool result = firstCondition.Or(SomeFunction, param1, param2, param3);

// Displaying the result
Console.WriteLine($"Result of the logical OR operation with a function taking three parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, bool>): A function taking three parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.

Returns:

  • bool: The result of the logical OR operation.

Or<T1, T2, T3, T4>(Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)

Performs a logical OR operation on the first boolean value and a function taking four parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes four parameters and returns a boolean
bool SomeFunction(double param1, bool param2, char param3, string param4) => /* Some logic based on the parameters */;

// Example parameter values
double param1 = 3.14;
bool param2 = true;
char param3 = 'A';
string param4 = "Hello";

// Using the Or method to perform a logical OR operation with a function taking four parameters
bool result = firstCondition.Or(SomeFunction, param1, param2, param3, param4);

// Displaying the result
Console.WriteLine($"Result of the logical OR operation with a function taking four parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, T4, bool>): A function taking four parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.

Returns:

  • bool: The result of the logical OR operation.

Or<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)

Performs a logical OR operation on the first boolean value and a function taking five parameters

and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes five parameters and returns a boolean
bool SomeFunction(char param1, int param2, string param3, double param4, bool param5) => /* Some logic based on the parameters */;

// Example parameter values
char param1 = 'A';
int param2 = 42;
string param3 = "Hello";
double param4 = 3.14;
bool param5 = true;

// Using the Or method to perform a logical OR operation with a function taking five parameters
bool result = firstCondition.Or(SomeFunction, param1, param2, param3, param4, param5);

// Displaying the result
Console.WriteLine($"Result of the logical OR operation with a function taking five parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, T4, T5, bool>): A function taking five parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.
  • value5 (T5): The fifth parameter for the function.

Returns:

  • bool: The result of the logical OR operation.

Certainly! Here's the README documentation for the OrNot extension methods:

OrNot

Performs a logical OR NOT operation on two boolean values.

// Example boolean values
bool firstCondition = true;
bool secondCondition = false;

// Using the OrNot method to perform a logical OR NOT operation
bool result = firstCondition.OrNot(secondCondition);

// Displaying the result
Console.WriteLine($"Result of the logical OR NOT operation: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (bool): The second boolean value.

Returns:

  • bool: The result of the logical OR NOT operation.

OrNot(Func other)

Performs a logical OR NOT operation on the first boolean value and a function returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that returns a boolean
bool SomeFunction() => /* Some logic */;

// Using the OrNot method to perform a logical OR NOT operation with a function
bool result = firstCondition.OrNot(() => SomeFunction());

// Displaying the result
Console.WriteLine($"Result of the logical OR NOT operation with a function: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func): A function returning a boolean.

Returns:

  • bool: The result of the logical OR NOT operation.

OrNot(Func<T, bool> other, T value)

Performs a logical OR NOT operation on the first boolean value and a function taking one parameter and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes one parameter and returns a boolean
bool SomeFunction(int parameter) => /* Some logic based on the parameter */;

// Example parameter value
int parameterValue = 42;

// Using the OrNot method to perform a logical OR NOT operation with a function taking one parameter
bool result = firstCondition.OrNot(SomeFunction, parameterValue);

// Displaying the result
Console.WriteLine($"Result of the logical OR NOT operation with a function taking one parameter: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T, bool>): A function taking one parameter and returning a boolean.
  • value (T): The parameter for the function.

Returns:

  • bool: The result of the logical OR NOT operation.

OrNot<T1, T2>(Func<T1, T2, bool> other, T1 value1, T2 value2)

Performs a logical OR NOT operation on the first boolean value and a function taking two parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes two parameters and returns a boolean
bool SomeFunction(int param1, string param2) => /* Some logic based on the parameters */;

// Example parameter values
int param1 = 42;
string param2 = "Hello";

// Using the OrNot method to perform a logical OR NOT operation with a function taking two parameters
bool result = firstCondition.OrNot(SomeFunction, param1, param2);

// Displaying the result
Console.WriteLine($"Result of the logical OR NOT operation with a function taking two parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, bool>): A function taking two parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.

Returns:

  • bool: The result of the logical OR NOT operation.

OrNot<T1, T2, T3, T4>(Func<T1, T2, T3, T4, bool> other, T1 value1, T2 value2, T3 value3, T4 value4)

Performs a logical OR NOT operation on the first boolean value and a function taking four parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes four parameters and returns a boolean
bool SomeFunction(double param1, bool param2, char param3, string param4) => /* Some logic based on the parameters */;

// Example parameter values
double param1 = 3.14;
bool param2 = true;
char param3 = 'A';
string param4 = "Hello";

// Using the OrNot method to perform a logical OR NOT operation with a function taking four parameters
bool result = firstCondition.OrNot(SomeFunction, param1, param2, param3, param4);

// Displaying the result
Console.WriteLine($"Result of the logical OR NOT operation with a function taking four parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, T4, bool>): A function taking four parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.

Returns:

  • bool: The result of the logical OR NOT operation.

OrNot<T1, T2, T3, T4, T5>(Func<T1, T2, T3, T4, T5, bool> other, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5)

Performs a logical OR NOT operation on the first boolean value and a function taking five parameters and returning a boolean.

// Example boolean value
bool firstCondition = true;

// Example function that takes five parameters and returns a boolean
bool SomeFunction(char param1, int param2, string param3, double param4, bool param5) => /* Some logic based on the parameters */;

// Example parameter values
char param1 = 'A';


int param2 = 42;
string param3 = "Hello";
double param4 = 3.14;
bool param5 = true;

// Using the OrNot method to perform a logical OR NOT operation with a function taking five parameters
bool result = firstCondition.OrNot(SomeFunction, param1, param2, param3, param4, param5);

// Displaying the result
Console.WriteLine($"Result of the logical OR NOT operation with a function taking five parameters: {result}");

Parameters:

  • boolean (bool): The first boolean value.
  • other (Func<T1, T2, T3, T4, T5, bool>): A function taking five parameters and returning a boolean.
  • value1 (T1): The first parameter for the function.
  • value2 (T2): The second parameter for the function.
  • value3 (T3): The third parameter for the function.
  • value4 (T4): The fourth parameter for the function.
  • value5 (T5): The fifth parameter for the function.

Returns:

  • bool: The result of the logical OR NOT operation.

Xor

Xor

Performs a logical XOR operation on two boolean values.

using UtilityLibrary.Core;

bool result = true.Xor(false);
bool firstCondition = true;
bool secondCondition = false;

bool result = firstCondition.Xor(secondCondition);

// Result: true

Parameters

  • boolean (bool): The first boolean value.
  • other (bool): The second boolean value.

Returns

  • bool: The result of the logical XOR operation.

Clone this wiki locally