我有一个在类级别声明的对象,它发出 CA2000 警告。如何从下面的代码中消除 CA2000 警告?
public partial class someclass : Window
{
System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog()
{
AddExtension = true,
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "xsd",
FileName = lastFileName,
Filter = "XML Schema Definitions (*.xsd)|*.xsd|All Files (*.*)|*.*",
InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop),
RestoreDirectory = true,
Title = "Open an XML Schema Definition File"
};
}
警告是 - 警告 CA2000 在方法“SIMPathFinder.SIMPathFinder()”中,对象“new OpenFileDialog()”未沿所有异常路径处理。在对对象“new OpenFileDialog()”的所有引用超出范围之前调用 System.IDisposable.Dispose。