CA2000 は、IDisposable インターフェイスに関する警告です。
CA2000 : Microsoft.Reliability: メソッド 'ImportProcessor.GetContext(string)' で、オブジェクト 'c' へのすべての参照が範囲外になる前に、オブジェクト 'c' で System.IDisposable.Dispose を呼び出します。
私のメソッドは、次のようにコンテキストのキャッシュを保存するために使用されます。
public class RegionContext : IDisposable { /* Implement Dispose() here */ }
private Dictionary<string, RegionContext> contextCache = new ..... ();
public RegionContext GetContext(string regionCode)
{
RegionContext rc = null;
if (!this.contextCache.TryGetValue(regionCode.ToUpper(), out rc))
{
rc = new RegionContext(regionCode);
this.contextCache.Add(regionCode.ToUpper(), rc);
}
return rc;
}
using()
このコンパイラ警告を修正するステートメントをどこで使用しますか?
contextCache
私の外部クラスは、実際には、独自の実装で内容を反復して破棄します。私はそれを抑制すべきですか、それともこの警告を正しく取り除く方法はありますか?