Getting ready for Nullable Reference Types Looking forward for C# Nullable Reference Types in C# 8.0. I do not like to use the preview implementation in a production code though, so just went with these simple helper classes intending them to be upgraded to new syntax by search and replace when time comes. 

Usage sample:

static void Main(string[] args)
{
    var johnk = new FullName("John", "F.", "Kennedy");
    var johnd = new FullName("John", null, "Do");
    var johnn = new FullName("John", null, null); // throws
}


Where business class is:

class FullName
{     
    public FullName(Some&lt;string&gt; first, Option&lt;string&gt; middle, Some&lt;string&gt; last) =&gt;
        (First, Middle, Last) = (first, middle, last);

    public string First { get; }
    public string Middle { get; }
    public string Last { get; }
}


Library code:

[DebuggerStepThrough]
struct Some&lt;T&gt; where T : class
{
    public static implicit operator Some&lt;T&gt;(T value) =&gt; 
        new Some&lt;T&gt;(value ?? throw new ArgumentNullException());

    public static implicit operator T(Some&lt;T&gt; some) =&gt; 
        some.Value ?? throw new ArgumentNullException();

    Some(T value) =&gt; Value = value; 
    T Value { get; }
}


And

[DebuggerStepThrough]
struct Option&lt;T&gt; where T : class
{
    public static implicit operator Option&lt;T&gt;(T value) =&gt; 
        new Option&lt;T&gt;(value);

    public static implicit operator T(Option&lt;T&gt; some) =&gt; 
        some.Value;

    Option(T value) =&gt; Value = value;
    T Value { get; }
}


Nothing fancy, just does the job and it would be easy to upgrade syntax…
There are some disadvantanges about this solution. You not only loose the argument-name inside the exception but if you are using ReSharper then you won't be able to quick-fix this in future.

Thus I think it's not necessary to create such helpers because as soon as the new feature is there, ReSharper will probably have nice quick-fix for that so it'll turn all if(foo == null) throw new ArgumentException(..) into the new syntax. I doubt ReSharper will be able to quick-fix this.

Besides if you properly decorate your code with the [NotNull] and [CanBeNull] attributes, you are half-way safe. Since I started using them, It's been ages that I last saw a NullReferenceExcepiton or ArgumentNullExcepiton.



I also find ReSharper's naming convention more appealing. This means 


Some becomes NotNull and
Option becomes CanBeNull