Skip to content

Instantly share code, notes, and snippets.

@mterwoord
Created February 23, 2017 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mterwoord/fed8ea6b4b210aa4366e8fdf4c3bfcec to your computer and use it in GitHub Desktop.
Save mterwoord/fed8ea6b4b210aa4366e8fdf4c3bfcec to your computer and use it in GitHub Desktop.
Conversion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TerWoord.Framework.Contracts.JetBrains.Annotations;
namespace TerWoord.Framework
{
[DebuggerDisplay("{Value}")]
public sealed class ValueContainer<T>
{
public ValueContainer(T initialValue = default(T))
{
Value = initialValue;
}
public T Value
{
get;
set;
}
public static implicit operator T([NotNull] ValueContainer<T> container)
{
if (container == null)
{
throw new ArgumentNullException(nameof(container));
}
return container.Value;
}
public static implicit operator ValueContainer<T>(T value)
{
return new ValueContainer<T>(value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment