English 中文(简体)
确定装货的接口 用户思考
原标题:Define interface for loading custom UserControls through reflection

I m loading custom user controls into my form using reflection. I would like all my user controls to have a "Start" and "End" method so they should all be like:

public interface IStartEnd
{
    void Start();
    void End();
}

public class AnotherControl : UserControl, IStartEnd
{            
    public void Start()
    { }

    public void End()
    { }
}

我想通过反思装满,但以下工作显然胜过,因为接口不能继承一个类别:

public interface IMyUserControls : UserControl, IInit, IDispose
{

}
最佳回答

您可以暂时强制实施以下限制:实施<代码>IMyUserControls: IInit, IDispose的类别也属于用户Control。 有理由认为,为贵方提供海关管制的开发商知道控制的要求,因此我看不到在操作时间进行检查的问题。

问题回答

我看不出使用情况,通过思考对用户进行控制就需要知道控制的名称。 是否使用议会。 如果你能动地装上议会,或用全称与活动分子一起使用,则创造活力。 创造活力,使《刑法》能够确定需要装上何种组装。

如果你想避免具体说明用户控制类型名称,那么你就可以将装货组装满大会。 GetTypes()和寻找一种能够实施您的接口的类型。 如果你能够保证大会只包含一种控制,那么这只会奏效。

它像你试图做的那样,与棱晶(和复合应用区)的做法非常相似。 在以下条款中读一读:

这里有一些例子,这种模式得到广泛使用。

我希望这一帮助。

页: 1





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签