Skip to content

Instantly share code, notes, and snippets.

@WooCode
Last active December 15, 2015 07:40
Show Gist options
  • Save WooCode/5225544 to your computer and use it in GitHub Desktop.
Save WooCode/5225544 to your computer and use it in GitHub Desktop.
Simple utility class to indicate that method result is cloned.
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