本文是小编为大家收集整理的关于扩展属性问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我要扩展TextBox和ComboBox的一些属性
例如.
头等舱->extTextBox:继承文本框
属性->//FocusBackColorChange
//Is_Numeric_Only
//Is_DropDownList
二等->extComboBox:继承组合框
属性//FocusBackColorChange
//Is_Numeric_Only
第三类->Common_Properties
属性 FocusBackColorChange
Is_Numeric_Only
现在上面的两个属性是常见的,同样我必须扩展列表框、选项按钮、复选框,所有这些属性都有两个共同的属性
对于 Ex.FocusBackColorChange
Tagged_Data_Column_Name
Tagged_Data_Table_Name .....等 20 个属性.
问题是如何继承"第一类"和"第二类"中的"第三类",因为点网不支持多重继承,如果我使用接口,我必须再次为所有公共属性提供实现,它将是双重工作
请给我任何解决方案.
谢谢
Sukhen Dass
推荐答案
我之前也做过同样的事情,只是硬着头皮,用了一个接口,在每个继承的控件中实现..
这在某种程度上是必要的,因为(例如)我实现了一些新属性,这些属性根据控件执行不同的实现.
它还允许我将这些控件与未实现该接口的其他控件混合在一起 - 因此我可以在尝试访问这些属性之前检查它们是否实现了,在这些属性中我对某些控件有一个通用引用(例如,我突出显示了使用错误的控件一个属性"IsInError"和我的验证块可以测试控件是否实现了接口,如果实现了就设置 IsInerror.
如果您不需要它们作为属性,则可以使用扩展方法并实现 Get_Is_Numeric_Only 和 Set_Is_Numeric_Only
您可以(取决于范围)将每个有问题的控件添加到实现公共属性的用户控件中,并公开您需要的任何其他控件 - 但是当涉及不同的控件时,这可能会过于复杂.
问题描述
I have to extend some properties of TextBox and ComboBox
For ex.
First Class-> extTextBox:Inherits TextBox
Properties-> //FocusBackColorChange
//Is_Numeric_Only
//Is_DropDownList
Second Class-> extComboBox:Inherits ComboBox
Properties //FocusBackColorChange
//Is_Numeric_Only
Third Class-> Common_Properties
Properties FocusBackColorChange
Is_Numeric_Only
Now Two Properties from above are common and similarly I have to extend listbox,optionbutton,checkbox and all will have two properties in common
For Ex.FocusBackColorChange
Tagged_Data_Column_Name
Tagged_Data_Table_Name.....etc 20 properties.
The Problem Is how to Inherit the "Third Class" in "First Class" and "Second Class" as Dot net does not support Multiple Inheritance and If I use Interface I have to give the implementation for All the common properties again and It will be double job
Please,suggest me any solution.
Thanks
Sukhen Dass
推荐答案
I''ve done the same thing previously, and just bitten the bullet, used an interface, and implemented in each inherited control..
This was necessary somewhat as (for example) I implemented some new properties that deeded different implementation depending on the control.
it also allowed me to mix these controls with others that did not implement the interface - so I could check if they did before trying to access these properties, where I had a generic reference to some control (e.g. I highlighted controls that were in error using a property "IsInError" and my validation block could just test if the control implemented the interface, and set IsInerror if it did/.
If you don''t need them to be properties, you could use extension methods and implement Get_Is_Numeric_Only and Set_Is_Numeric_Only
you could (depending on the scope) add each of the controls in question to a user control that implements the common properties, and exposes any others you need - but this can be over complex when different controls are involved.