Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有类型参数的自定义控件_C#_Winforms_Oop_Design Patterns - Fatal编程技术网

C# 具有类型参数的自定义控件

C# 具有类型参数的自定义控件,c#,winforms,oop,design-patterns,C#,Winforms,Oop,Design Patterns,我正在构建一个扩展DataGridView的WinForms自定义控件 interface IMyControl<A, B> { } public partial class MyControl<A, B> : DataGridView, IMyControl<A, B> { } “Infrastructure.MyControl.Dispose(bool)”:未找到覆盖MyControl.Designer.cs的合适方法 不能有通用控件 试试这个: int

我正在构建一个扩展DataGridView的WinForms自定义控件

interface IMyControl<A, B> { }
public partial class MyControl<A, B> : DataGridView, IMyControl<A, B>
{
}
“Infrastructure.MyControl.Dispose(bool)”:未找到覆盖MyControl.Designer.cs的合适方法


不能有通用控件

试试这个:

interface IMyControl<A, B> { }
public partial abstract class MyControlBase<A, B> : DataGridView, IMyControl<A, B>
{
    // Generic code goes here
}

// Create non-generic wrappers for the generic base class
public partial class MyControl_One : DataGridView, MyControlBase<SomeType, OtherType>
{
     // Type-specific (if any) code goes here
}
public partial class MyControl_Two : DataGridView, MyControlBase<MyType, YourType>
{
     // Type-specific (if any) code goes here
}
接口IMyControl{}
公共部分抽象类MyControlBase:DataGridView,IMyControl
{
//通用代码在这里
}
//为泛型基类创建非泛型包装
公共部分类MyControl\u One:DataGridView,MyControlBase
{
//此处显示特定于类型的(如果有)代码
}
公共部分类MyControl\u二:DataGridView、MyControlBase
{
//此处显示特定于类型的(如果有)代码
}

在泛型基类中保留您当前拥有的任何泛型代码。包装类可以非常精简,因为这样只能提供一个非泛型控件来添加到表单中。

抽象MyControlBase emtpy的主体也是如此?不,它应该包含泛型代码。我编辑了我的答案以便澄清。谢谢。似乎我不需要界面
IMyControl
interface IMyControl<A, B> { }
public partial abstract class MyControlBase<A, B> : DataGridView, IMyControl<A, B>
{
    // Generic code goes here
}

// Create non-generic wrappers for the generic base class
public partial class MyControl_One : DataGridView, MyControlBase<SomeType, OtherType>
{
     // Type-specific (if any) code goes here
}
public partial class MyControl_Two : DataGridView, MyControlBase<MyType, YourType>
{
     // Type-specific (if any) code goes here
}