开发者

Quickly create a wrappers for classes to count undisposed instances?

Is there any tool or library that will let me easily wrap a class, say DbDataReader with another class called, say WDbDataReader, for debugging purposes?

My particular problem is that I think my code is not properly calling DbDataReader's Dispose. I first though about subclassing DbDataReader and having a sta开发者_StackOverflowtic int that counts created instances that have not been disposed. The problem is that I don't create the instance from my code but by calling OleDbCommand's ExecuteReader method.

So now I want to create a class that would look something like this:

public class WDbDataReader
{
    private static int _Counter = 0;
    private DbDataReader _Source;

    public WDbDataReader(DbDataReader source)
    {
        _Source = source;
        _Counter++;
    }

    public void Dispose()
    {
        _Counter--;
        _Source.Dispose();
    }

    // implement all used DbDataReader methods here
}

And then surround all calls to OleDbCommand's ExecuteReader method with a new WDbDataReader(...). So I was wondering if there is a quicker or automated way to do this because I might need to do it for several other classes in the future.

I'm not sure but I believe I could use Pex or Moles for this purpose. But I've been checking their tutorials and I believe that's way more advanced that what I need right now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜