简体   繁体   English

如何向密封类Arc添加属性

[英]How to add a property to the sealed class Arc

how can I add two new properties to the sealed Arc class. 如何向密封的Arc类添加两个新属性。 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. 我想扩展类,使其具有double属性以容纳double值,并具有string属性以容纳对象的名称。 My first try was via the Tag property but this can only hold the double value OR the object name. 我的第一次尝试是通过Tag属性,但是它只能容纳double值或对象名称。

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. 问题是我创建了一个带有43个圆弧对象的新用户控件,当鼠标进入圆弧时,另一个控件显示了输入段的值和名称。 So every arc uses the SAME MouseEntered function and I want to get the informations via the "object sender". 因此,每条弧线都使用SAME MouseEntered函数,我想通过“对象发送者”获得信息。

I hope anyone has a nice idea. 我希望任何人都有一个好主意。

You could use the composite pattern. 您可以使用复合模式。

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

You can't. 你不能。 It's sealed. 密封了 Either: 或者:

  1. Create a new class that contains an Arc as a property. 创建一个包含 Arc作为属性的新类。
  2. Store a tuple or some other object in Arc.Tag . 将元组或其他对象存储在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. 对于您的特定问题,我建议使用上面的#2或存储Dictionary<Arc, blahblahblah>Dictionary<string, blahblahblah> (按名称),并查找所需的信息。 #1 is a lot of overhead wrapping all the methods and properties you need for drawing, and probably more hassle than it's worth. #1花费了很多开销来包装您绘制所需的所有方法和属性,并且可能比它的价值还要麻烦。

You can't extend sealed clases. 您无法扩展密封的类别。

Try creating your own class and having Arc as a class member, and expose this member functions. 尝试创建自己的类并将Arc作为类成员,并公开此成员函数。

Best regards. 最好的祝福。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM