Last active
December 15, 2015 07:40
-
-
Save WooCode/5225544 to your computer and use it in GitHub Desktop.
Simple utility class to indicate that method result is cloned.
This file contains hidden or 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
class Program | |
{ | |
private static Tiger _tiger; | |
public static void Main(string[] args) | |
{ | |
Tiger myTiger = GetYourOwnTiger(); | |
// or var myTiger = GetYourOwnTiger().Value; | |
// or var myTiger = (Tiger)GetYourOwnTiger(); | |
Console.WriteLine(_tiger.Equals(myTiger)); // FALSE | |
Console.ReadLine(); | |
} | |
static ClonedResult<Tiger> GetYourOwnTiger() | |
{ | |
_tiger = new Tiger(); | |
_tiger.Age = 28; | |
_tiger.Color = "yellow"; | |
return _tiger; | |
} | |
} | |
class ClonedResult<T> | |
{ | |
private ClonedResult(T value) | |
{ | |
Value = ObjectCopier.Clone(value); | |
} | |
public T Value { get; set; } | |
public static implicit operator ClonedResult<T>(T value) | |
{ | |
return new ClonedResult<T>(value); | |
} | |
public static implicit operator T(ClonedResult<T> clonedResult) | |
{ | |
return clonedResult.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment