Created
April 3, 2017 04:32
-
-
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
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
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