Reputation: 54791
I have an immutable Money type (ammount and currency) and I'm copying an example I saw here.
They implement the deep copy like so:
public object DeepCopy(object value)
{
return new Money(((Money) value).Amount, ((Money) value).Currency);
}
Which is pointless and inefficient for immutables. But as I don't know the NHibernate libs inside out, I want to know if it is nessasary, and if it's safe to do this:
public object DeepCopy(object value)
{
return value;
}
The only difference I can foresee is if somewhere in NHibernate they are relying on object
's !=
operator returning true
. But that would be nasty, so I doubt that's going on, but I'd like confirmation.
Also, please note my money is a class
, not a struct
.
Upvotes: 0
Views: 108
Reputation: 30813
DeepCopy is there to have a copy for change tracking which is pointless for immutable types so your implementation is typical for all immutable types
public bool IsMutable
{
get { return false; }
}
public object DeepCopy(object value)
{
return value;
}
Upvotes: 1