CA2000 is a warning regarding the IDisposable interface:
CA2000 : Microsoft.Reliability : In method 'ImportProcessor.GetContext(string)', call System.IDisposable.Dispose on object 'c' before all references to it are out of scope.
My method is used to store a cache of context like so:
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;
}
Where would you use the using()
statement that fixes this compiler warning?
My outer class actually does iterate and dispose of the contents in the contextCache
in its own implementation. Shall I suppress it, or is there a way to correctly get rid of this warning?