我有一个对象是在给出CA2000警告的类级别声明的。我如何摆脱下面代码中的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"
};
}
该警告是 - ')的新的OpenFileDialog(' 警告CA2000在方法 'SIMPathFinder.SIMPathFinder()',对象不被沿所有的异常路径设置。调用System.IDisposable.Dispose对象的新OpenFileDialog()'之前,所有对它的引用超出范围。
你的意思是解决警告的原因?或隐藏它,所以它不显示? –