Skip to content

Instantly share code, notes, and snippets.

@svermeulen
Created April 3, 2017 04:32
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save svermeulen/a6929e6e26f2de2cc697d24f108c5f85 to your computer and use it in GitHub Desktop.
Save svermeulen/a6929e6e26f2de2cc697d24f108c5f85 to your computer and use it in GitHub Desktop.
C# class to wrap convert value types to reference types by wrapping them in a reference type
public class Ref<T> where T: struct
{
T _value;
public Ref(T value)
{
_value = value;
}
public T Value
{
get { return _value; }
set { _value = value; }
}
public override string ToString()
{
return _value.ToString();
}
public static implicit operator T(Ref<T> wrapper)
{
return wrapper.Value;
}
public static implicit operator Ref<T>(T value)
{
return new Ref<T>(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment