Class GlobalClassExtensions
Extension methods for all classes.
Inheritance
System.Object
GlobalClassExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Annex.Global
Assembly: Annex.dll
Syntax
[PublicAPI]
public static class GlobalClassExtensions
Methods
| Improve this Doc View SourceNullIf<T>(T, T)
Returns
null
if the source value is equal to the provided value.
Declaration
public static T NullIf<T>([NotNull] this T this, [NotNull] T value)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | this | The source value. |
T | value | The value to compare. |
Returns
Type | Description |
---|---|
T | null if the source value is equal to the provided value, otherwise false . |
Type Parameters
Name | Description |
---|---|
T | The type of the value. |
Examples
"UnwantedValue".NullIf("UnwantedValue"); // null
"WantedValue".NullIf("UnwantedValue"); // WantedValue
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
this or value is null .
|
NullIf<T>(T, T, IEqualityComparer<T>)
Returns
null
if the source value is equal to the provided value.
Declaration
public static T NullIf<T>([NotNull] this T this, [NotNull] T value, [NotNull] IEqualityComparer<T> comparer)
where T : class
Parameters
Type | Name | Description |
---|---|---|
T | this | The source value. |
T | value | The value to compare. |
System.Collections.Generic.IEqualityComparer<T> | comparer | The comparer implementation to use to check for equality. |
Returns
Type | Description |
---|---|
T | null if the source value is equal to the provided value, otherwise false . |
Type Parameters
Name | Description |
---|---|
T | The type of the value. |
Examples
"UnwantedValue".NullIf("UnwantedValue", EqualityComparer<T>.Default); // null
"WantedValue".NullIf("UnwantedValue", EqualityComparer<T>.Default); // WantedValue
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
this , value , or comparer is null .
|