IDISP007 should not be triggered when an instance is created in a static method of a type and then passed to a private constructor of the same type.
namespace YourNamespace;
public sealed class MyFile : IDisposable
{
private readonly LiteDatabase _database;
private MyFile (LiteDatabase database)
{
_database = database;
}
public static MyFile Open(string filePath)
{
LiteDatabase? db;
try
{
db = new LiteDatabase(filePath);
// setup using db...
return new MyFile (db);
}
catch
{
db?.Dispose();
throw;
}
}
public void Dispose()
{
// This triggers IDISP0007
_database.Dispose();
}
}
IDISP007 should not be triggered when an instance is created in a static method of a type and then passed to a private constructor of the same type.