Class UpdateUtils
Provides neat little code-shortcuts for updating properties.
public static class UpdateUtils
- Inheritance
-
objectUpdateUtils
Methods
Swap<T>(ref T, ref T)
Swaps the content of two fields.
public static void Swap<T>(ref T value1, ref T value2)
Parameters
value1TThe first field which will afterwards carry the content of
value2.value2TThe first field which will afterwards carry the content of
value1.
Type Parameters
TThe type of objects to swap.
To<T>(T, ref T, Action)
Updates a value and calls back a delegate if the original value actually changed.
public static void To<T>(this T value, ref T original, Action updated)
Parameters
valueTThe new value.
originalTThe original value to update.
updatedActionGets called if value is different from original.
Type Parameters
TThe type of data to update.
To<T>(T, ref T, ref bool)
Updates a value and sets a boolean flag to true if the original value actually changed.
public static void To<T>(this T value, ref T original, ref bool updated)
Parameters
valueTThe new value.
originalTThe original value to update.
updatedboolGets set to
trueif value is different from original.
Type Parameters
TThe type of data to update.
To<T>(T, ref T, ref bool, ref bool)
Updates a value and sets two boolean flags to true if the original value actually changed.
public static void To<T>(this T value, ref T original, ref bool updated1, ref bool updated2)
Parameters
valueTThe new value.
originalTThe original value to update.
updated1boolGets set to
trueif value is different from original.updated2boolGets set to
trueif value is different from original.
Type Parameters
TThe type of data to update.
To<TIn, TOut>(TIn, Func<TIn, TOut>)
Immediately invokes the specified action with the value. Useful for applying null-coalescing operator.
public static TOut To<TIn, TOut>(this TIn value, Func<TIn, TOut> action) where TIn : notnull
Parameters
valueTInThe value.
actionFunc<TIn, TOut>The action to invoke.
Returns
- TOut
Type Parameters
TInTOut
Examples
This allows you to write:
Uri? uri = nullableString?.To(x => new Uri(x);
Instead of:
Uri? uri = nullableString == null ? null : new Uri(nullableString);