Skip to content

Instantly share code, notes, and snippets.

@SuicSoft
Last active November 9, 2015 08:00
Show Gist options
  • Save SuicSoft/b66e88333fa18f9215dc to your computer and use it in GitHub Desktop.
Save SuicSoft/b66e88333fa18f9215dc to your computer and use it in GitHub Desktop.
Async ref arguments c#
/// <summary>
/// Ref for async methods or tasks
/// </summary>
/// <typeparam name="T">The return or set type</typeparam>
public class AsyncRef<T>
{
/// <summary>
/// Initailizes the AsyncRef
/// </summary>
/// <param name="get">The getter</param>
/// <param name="set">The setter</param>
/// <exception cref="System.NullReferenceException">Thrown when a value is null</exception>
/// <seealso cref="Get"/>
/// <seealso cref="Set"/>
public AsyncRef(Func<T> get, Action<T> set)
{
if (get == null) throw new NullReferenceException("get"); //Check if getter is null.
if (set == null) throw new NullReferenceException("set"); //Check if setter is null.
//Sets values.
Get = get; //Sets the getter's value.
Set = set; //Sets the setter's value.
}
/// <summary>
/// The getter
/// </summary>
public Func<T> Get { get; set; }
/// <summary>
/// The setter
/// </summary>
public Action<T> Set { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment