Skip to content

Instantly share code, notes, and snippets.

@rorymurphy
Created April 18, 2017 04:15
Show Gist options
  • Save rorymurphy/e760668c2c20e7a597ccab350aa3a374 to your computer and use it in GitHub Desktop.
Save rorymurphy/e760668c2c20e7a597ccab350aa3a374 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Text;
namespace System
{
public struct NonNullable<T> where T : class
{
public NonNullable(T value)
{
if(value == null) { throw new ArgumentNullException(nameof(T)); }
this.Value = value;
}
public T Value { get; private set; }
public static implicit operator T(NonNullable<T> toConvert)
{
return toConvert.Value;
}
public static explicit operator NonNullable<T>(T value)
{
return new NonNullable<T>(value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment