How can I clone a custom entity?

This article explains how to clone a custom Line entity. Custom entities can be easily cloned adding the protected copy constructor and overriding the Clone() method. A complete example follows.

class MyLine : Line
{
   private float price;

   public MyLine(double x1, double y1, double x2, double y2, float thePrice)
      : base(x1, y1, x2, y2)
   {
      price = thePrice;
   }

   protected MyLine(MyLine another)
      : base(another)
   {
      price = another.price;
   }

   public override object Clone()
   {
      return new MyLine(this);
   }
} 
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.