C# CA2000:Microsoft.Reliability call System.IDisposable.Dispose在对象上的所有引用都超出范围之前
这个警告非常烦人,我已经读了很多帖子,建议解决这个问题的方法,但它们似乎不起作用 就我所见,我已经满足了下面代码中的所有场景,但我仍然得到了警告。我正在使用VS2010。我很想抑制它,但如果它不太难看,我宁愿修复它。有什么建议吗C# CA2000:Microsoft.Reliability call System.IDisposable.Dispose在对象上的所有引用都超出范围之前,c#,visual-studio-2010,code-analysis,C#,Visual Studio 2010,Code Analysis,这个警告非常烦人,我已经读了很多帖子,建议解决这个问题的方法,但它们似乎不起作用 就我所见,我已经满足了下面代码中的所有场景,但我仍然得到了警告。我正在使用VS2010。我很想抑制它,但如果它不太难看,我宁愿修复它。有什么建议吗 private LicenseModules CreateDataSource { get { // set default result LicenseModules re
private LicenseModules CreateDataSource
{
get
{
// set default result
LicenseModules result = null;
try
{
result = new LicenseModules();
// lookup the "Tools" class in the current entry assembly
var lookup = Assembly.GetEntryAssembly().GetTypes().FirstOrDefault(item => item.Name.Equals("Tools", StringComparison.Ordinal));
// ensure the lookup result is valid
if (lookup != null)
{
// lookup the Configuration property
var prop = lookup.GetProperty("Configuration", BindingFlags.Static | BindingFlags.Public);
// validate the lookup result
if (prop != null)
{
// read the current Configuration value
object value = prop.GetValue(lookup, null);
// ensure the read value is valid
if (value != null)
result = (value as Configuration).Solutions.LicenseModules;
}
}
// return current result
return result;
}
catch (Exception)
{
if (result != null)
{
result.Dispose();
}
throw;
}
}
}
在这里:
在未处理此处创建的实例的情况下,将新值分配给结果
:
result = new LicenseModules();
在指定新结果之前,应创建块并处理旧结果值:
if (value != null) {
result.Dipose();
result = (value as Configuration).Solutions.LicenseModules;
}
在这里:
在未处理此处创建的实例的情况下,将新值分配给结果
:
result = new LicenseModules();
在指定新结果之前,应创建块并处理旧结果值:
if (value != null) {
result.Dipose();
result = (value as Configuration).Solutions.LicenseModules;
}
在这里:
在未处理此处创建的实例的情况下,将新值分配给结果
:
result = new LicenseModules();
在指定新结果之前,应创建块并处理旧结果值:
if (value != null) {
result.Dipose();
result = (value as Configuration).Solutions.LicenseModules;
}
在这里:
在未处理此处创建的实例的情况下,将新值分配给结果
:
result = new LicenseModules();
在指定新结果之前,应创建块并处理旧结果值:
if (value != null) {
result.Dipose();
result = (value as Configuration).Solutions.LicenseModules;
}
另一个选项是删除第一个赋值,并在外部
if
块下方执行空检查:返回结果??新的许可证模块()代码>另一个选项是删除第一个赋值,并在外部if
块下方执行空检查:返回结果??新的许可证模块()代码>另一个选项是删除第一个赋值,并在外部if
块下方执行空检查:返回结果??新的许可证模块()代码>另一个选项是删除第一个赋值,并在外部if
块下方执行空检查:返回结果??新的许可证模块()代码>