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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…