Then you need to implement ICloneable
and replace
r.TryAddPackage((IPackage)ps);
with
r.TryAddPackage((IPackage)ps.Clone());
It's up to you to decide how Clone
should populate the new instance of PinnacleStock
that it returns.
At the most basic level, you could say
public PinnacleStock : ICloneable {
public PinnacleStock Clone() {
return (PinnacleStock)this.MemberwiseClone();
}
object ICloneable.Clone() {
return Clone();
}
// details
}
This will just do a shallow copy of PinnacleStock
. Only you know if this is the correct semantics for your domain.