Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose moved to base #386

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ internal void PinChanged(object sender, IOExpanderInputChangedEventArgs e)
Console.WriteLine(ex.ToString());
}
}

public override void Dispose()
{

}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Meadow.Hardware;
using Meadow.Hardware;

namespace Meadow.Foundation.ICs.IOExpanders
{
Expand All @@ -9,12 +8,15 @@ public class DigitalOutputPort : DigitalOutputPortBase
{
Mcp23x08 _mcp;

public override bool State {
public override bool State
{
get => this.state;
set {
set
{
_mcp.WriteToPort(this.Pin, value);
}
} protected bool state;
}
protected bool state;

public DigitalOutputPort(
Mcp23x08 mcpController,
Expand All @@ -26,21 +28,17 @@ public DigitalOutputPort(
_mcp = mcpController;
}

public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
protected override void Dispose(bool disposing)
{
// TODO: we should consider moving this logic to the finalizer
// but the problem with that is that we don't know when it'll be called
// but if we do it in here, we may need to check the _disposed field
// elsewhere

if (!disposed) {
if (disposing) {
if (!disposed)
{
if (disposing)
{
this.state = false;
_mcp.ResetPin(this.Pin);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Meadow.Hardware;
using Meadow.Hardware;

namespace Meadow.Foundation.ICs.IOExpanders
{
Expand All @@ -22,21 +21,15 @@ public override bool State
public DigitalOutputPort(
x74595 x74595,
IPin pin,
bool initialState,
bool initialState,
OutputType outputType)
: base(pin, (IDigitalChannelInfo)pin.SupportedChannels[0], initialState, outputType)
{

_x74595 = x74595;
}

public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
protected override void Dispose(bool disposing)
{
if (!disposed)
{
Expand All @@ -47,12 +40,6 @@ protected virtual void Dispose(bool disposing)
disposed = true;
}
}

// Finalizer
~DigitalOutputPort()
{
Dispose(false);
}
}
}
}