Christian
Christian

Reputation: 344

How to add a property to the sealed class Arc

how can I add two new properties to the sealed Arc class. I want to extend the class with a double property to hold a double value and a string property to hold the name of the object. My first try was via the Tag property but this can only hold the double value OR the object name.

The problem is that I created a new user control with 43 arc objects and when the mouse entered an arc another control shows up the value and the name of the entered segment. So every arc uses the SAME MouseEntered function and I want to get the informations via the "object sender".

I hope anyone has a nice idea.

Upvotes: 2

Views: 2587

Answers (3)

Oscar
Oscar

Reputation: 13970

You can't extend sealed clases.

Try creating your own class and having Arc as a class member, and expose this member functions.

Best regards.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190986

You could use the composite pattern.

class SuperArc
{
   Arc Arc { get; set; }
   // other properties.
}

Upvotes: 5

lc.
lc.

Reputation: 116528

You can't. It's sealed. Either:

  1. Create a new class that contains an Arc as a property.
  2. Store a tuple or some other object in Arc.Tag.
  3. Decorate the Arc with attributes

For your particular problem, I would suggest #2 above or to store a Dictionary<Arc, blahblahblah> or Dictionary<string, blahblahblah> (by name) and look up the info you need. #1 is a lot of overhead wrapping all the methods and properties you need for drawing, and probably more hassle than it's worth.

Upvotes: 3

Related Questions