-
Notifications
You must be signed in to change notification settings - Fork 0
Generic Extensions
Andrzej Kebab edited this page Jan 23, 2024
·
1 revision
This utility library provides extension methods for generic operations, allowing you to perform various checks and conversions on values.
Checks if the value is null.
// Example usage with a string
string stringValue = null;
bool isNull = stringValue.IsNull();
Console.WriteLine($"Is null: {isNull}");
// Output: Is null: TrueParameters:
-
value(T): The value to check.
Returns:
- bool: True if the value is null, false otherwise.
Checks if the value is not null.
// Example usage with an integer
int intValue = 42;
bool isNotNull = intValue.IsNotNull();
Console.WriteLine($"Is not null: {isNotNull}");
// Output: Is not null: TrueParameters:
-
value(T): The value to check.
Returns:
- bool: True if the value is not null, false otherwise.
Checks if the value is the default value for its type.
// Example usage with a double
double doubleValue = 0.0;
bool isEmpty = doubleValue.IsEmpty();
Console.WriteLine($"Is empty: {isEmpty}");
// Output: Is empty: TrueParameters:
-
value(T): The value to check.
Returns:
- bool: True if the value is the default value for its type, false otherwise.
Checks if the value is not the default value for its type.
// Example usage with a boolean
bool boolValue = true;
bool isNotEmpty = boolValue.IsNotEmpty();
Console.WriteLine($"Is not empty: {isNotEmpty}");
// Output: Is not empty: TrueParameters:
-
value(T): The value to check.
Returns:
- bool: True if the value is not the default value for its type, false otherwise.
Converts the value to a nullable type.
// Example usage with an integer
int intValue = 42;
int? nullableInt = intValue.ToNullable();
Console.WriteLine($"Nullable value: {nullableInt}");
// Output: Nullable value: 42Parameters:
-
value(T): The value to convert.
Returns:
- T?: The value as a nullable type, or null if the value is the default value for its type.
Checks if the value is equal to any of the provided values.
// Example usage with a string
string stringValue = "apple";
bool equalsAny = stringValue.EqualsAny("orange", "banana", "apple");
Console.WriteLine($"Equals any: {equalsAny}");
// Output: Equals any: TrueParameters:
-
value(T): The value to check. -
values(T[]): The values to compare to.
Returns:
- bool: True if the value is equal to any of the provided values, false otherwise.
Checks if the value is not equal to any of the provided values.
// Example usage with an integer
int intValue = 42;
bool equalsNone = intValue.EqualsNone(10, 20, 30);
Console.WriteLine($"Equals none: {equalsNone}");
// Output: Equals none: TrueParameters:
-
value(T): The value to check. -
values(T[]): The values to compare to.
Returns:
- bool: True if the value is not equal to any of the provided values, false otherwise.
Checks if the value has all the specified flags.
// Example usage with an enum
[Flags]
enum MyEnum { A = 1, B = 2, C = 4 }
MyEnum value = MyEnum.A | MyEnum.B;
bool hasFlags = value.HasFlags(MyEnum.A, MyEnum.B);
Console.WriteLine($"Has flags: {hasFlags}");
// Output: Has flags: TrueParameters:
-
value(T): The value to check. -
flags(T[]): The flags to check for.
Returns:
- bool: True if the value has all the specified flags, false otherwise.