我再次遇到另一个CA2000警告。带嵌套构造函数的CA2000
下面的代码生成的CA2000警告:
// Use an emulated GPS device
nmeaInterpreter.Start(new VirtualDevice(new NmeaEmulator()));
下面的警告出现:
CA2000 : Microsoft.Reliability : In method 'GpsService.Start()', call System.IDisposable.Dispose on object 'new NmeaEmulator()' before all references to it are out of scope.
我已经检查过微软的CA2000文档,但无法找到一个很好的例子如何处理嵌套的构造函数。很显然,我不想将自己的参考存储在模拟器中。我想引用只传递给构造函数。
是C#创建一个临时对象,我需要处置的引擎盖下?
什么是'VirtualDevice'?什么是构造函数签名? –