Created
April 18, 2017 04:15
-
-
Save rorymurphy/e760668c2c20e7a597ccab350aa3a374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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