我知道这不是标准做法,但是是否有任何缺点或更好的替代方法来执行以下操作?我只是想确保正确使用代码,而 .NET 不会为您做任何事情来确保它。
public class MyClass : IDisposable
public void Dispose()
{
// Some managed shutdown logic...
GC.SuppressFinalize(this);
}
#if DEBUG
// Why is ConditionalAttribute not allowed if you can still achieve this with compiler directives?
// [Conditional("DEBUG")]
~SFtpClient()
{
Debug.Fail("This class is IDisposable and should be wrapped by using {}");
}
#endif
}