Class UpdateUtils
Provides neat little code-shortcuts for updating properties.
Namespace: NanoByte.Common
Assembly: NanoByte.Common.dll
Syntax
public static class UpdateUtils : Object
Methods
Swap<T>(ref T, ref T)
Swaps the content of two fields.
Declaration
public static void Swap<T>(ref T value1, ref T value2)
Parameters
Type | Name | Description |
---|---|---|
T | value1 | The first field which will afterwards carry the content of |
T | value2 | The first field which will afterwards carry the content of |
Type Parameters
Name | Description |
---|---|
T | The type of objects to swap. |
To(String, ref String, Action)
Updates a value and calls back a delegate if the original value actually changed.
Declaration
public static void To(this string value, ref string original, Action updated)
Parameters
Type | Name | Description |
---|---|---|
String | value | The new value. |
String | original | The original value to update. |
Action | updated | Gets called if value is different from original. |
To(String, ref String, ref Boolean)
Updates a value and sets a boolean flag to true
if the original value actually changed
Declaration
public static void To(this string value, ref string original, ref bool updated)
Parameters
Type | Name | Description |
---|---|---|
String | value | The new value |
String | original | The original value to update |
Boolean | updated | Gets set to |
To(String, ref String, ref Boolean, ref Boolean)
Updates a value and sets two boolean flags to true
if the original value actually changed
Declaration
public static void To(this string value, ref string original, ref bool updated1, ref bool updated2)
Parameters
Type | Name | Description |
---|---|---|
String | value | The new value |
String | original | The original value to update |
Boolean | updated1 | Gets set to |
Boolean | updated2 | Gets set to |
To<T>(T, ref T, Action)
Updates a value and calls back a delegate if the original value actually changed.
Declaration
public static void To<T>(this T value, ref T original, Action updated)
where T : struct, ValueType
Parameters
Type | Name | Description |
---|---|---|
T | value | The new value. |
T | original | The original value to update. |
Action | updated | Gets called if value is different from original. |
Type Parameters
Name | Description |
---|---|
T | The type of data to update. |
To<T>(T, ref T, ref Boolean)
Updates a value and sets a boolean flag to true
if the original value actually changed.
Declaration
public static void To<T>(this T value, ref T original, ref bool updated)
where T : struct, ValueType
Parameters
Type | Name | Description |
---|---|---|
T | value | The new value. |
T | original | The original value to update. |
Boolean | updated | Gets set to |
Type Parameters
Name | Description |
---|---|
T | The type of data to update. |
To<T>(T, ref T, ref Boolean, ref Boolean)
Updates a value and sets two boolean flags to true
if the original value actually changed.
Declaration
public static void To<T>(this T value, ref T original, ref bool updated1, ref bool updated2)
where T : struct, ValueType
Parameters
Type | Name | Description |
---|---|---|
T | value | The new value. |
T | original | The original value to update. |
Boolean | updated1 | Gets set to |
Boolean | updated2 | Gets set to |
Type Parameters
Name | Description |
---|---|
T | The 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.
Declaration
public static TOut To<TIn, TOut>(this TIn value, Func<TIn, TOut> action)
Parameters
Type | Name | Description |
---|---|---|
TIn | value | The value. |
Func<TIn, TOut> | action | The action to invoke. |
Returns
Type | Description |
---|---|
TOut |
Type Parameters
Name | Description |
---|---|
TIn | |
TOut |
Examples
This allows you to write:
Uri? uri = nullableString?.To(x => new Uri(x);
Instead of:
Uri? uri = nullableString == null ? null : new Uri(nullableString);