如何添加处置功能,一个C#用户控件? [英] How do I add Dispose functionality to a C# UserControl?
问题描述
我有实现用户控件的类。 2005年.NET,Dispose方法在MyClass.Designer.cs局部类文件看起来像这样将自动创建:
I have a class which implements UserControl. In .NET 2005, a Dispose method is automatically created in the MyClass.Designer.cs partial class file that looks like this:
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
如果我想补充我自己的处置功能,在那里我会把它?由于生成这个文件,我不想在这里添加代码和风险得到它吹走了。
If I want to add my own Dispose functionality, where would I put it? Since this file is generated, I don't want to add code here and risk it getting blown away.
推荐答案
在这样的情况下,我动产生的的Dispose
方法,将主文件和扩展。 Visual Studio的尊重这一点。
In such a case I move the generated Dispose
method to the main file and extend it. Visual Studio respects this.
这是另一种方法是使用部分方法(C#3.0)。
An other approach would be using a partial method (C# 3.0).
这篇关于如何添加处置功能,一个C#用户控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!