Correctly implement Dispose pattern in FormBase for use on derived classes

This commit is contained in:
Alexei Agüero Alba 2022-12-05 17:12:53 -05:00
parent c86ce7a9e0
commit 138199e811
No known key found for this signature in database
GPG Key ID: 255511EEC9BD8D03

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using TelegramBotBase.Args; using TelegramBotBase.Args;
using TelegramBotBase.Base; using TelegramBotBase.Base;
@ -17,7 +16,6 @@ namespace TelegramBotBase.Form
/// </summary> /// </summary>
public class FormBase : IDisposable public class FormBase : IDisposable
{ {
public NavigationController NavigationController { get; set; } public NavigationController NavigationController { get; set; }
public DeviceSession Device { get; set; } public DeviceSession Device { get; set; }
@ -432,14 +430,29 @@ namespace TelegramBotBase.Form
} }
} }
protected virtual void Dispose(bool disposing)
{
if (this.IsDisposed)
{
return;
}
if (disposing)
{
this.Client = null;
this.Device = null;
}
this.IsDisposed = true;
}
/// <summary> /// <summary>
/// Cleanup /// Cleanup
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
this.Client = null; Dispose(true);
this.Device = null; GC.SuppressFinalize(this);
this.IsDisposed = true;
} }
} }
} }