Skip to content

Commit 01978a6

Browse files
committed
Drop net7.0 target
.NET 7 is EOL since May. The only .NET 7 features we use are `ObjectDisposedException.ThrowIf` (moved to a throw helper) and some newer regex features. This feels a bit weird, but I suppose it is the expected course of action.
1 parent 64d67cd commit 01978a6

14 files changed

+42
-110
lines changed

src/Renci.SshNet/BaseClient.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,10 @@ protected virtual void Dispose(bool disposing)
448448
/// <summary>
449449
/// Check if the current instance is disposed.
450450
/// </summary>
451-
/// <exception cref="ObjectDisposedException">THe current instance is disposed.</exception>
451+
/// <exception cref="ObjectDisposedException">The current instance is disposed.</exception>
452452
protected void CheckDisposed()
453453
{
454-
#if NET7_0_OR_GREATER
455-
ObjectDisposedException.ThrowIf(_isDisposed, this);
456-
#else
457-
if (_isDisposed)
458-
{
459-
throw new ObjectDisposedException(GetType().FullName);
460-
}
461-
#endif // NET7_0_OR_GREATER
454+
ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
462455
}
463456

464457
/// <summary>

src/Renci.SshNet/Common/ChannelInputStream.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ public override void Write(byte[] buffer, int offset, int count)
116116
throw new ArgumentOutOfRangeException(nameof(offset), "offset or count is negative.");
117117
}
118118

119-
if (_isDisposed)
120-
{
121-
throw CreateObjectDisposedException();
122-
}
119+
ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
123120

124121
if (count == 0)
125122
{
@@ -208,10 +205,5 @@ public override long Position
208205
get { return _totalPosition; }
209206
set { throw new NotSupportedException(); }
210207
}
211-
212-
private ObjectDisposedException CreateObjectDisposedException()
213-
{
214-
return new ObjectDisposedException(GetType().FullName);
215-
}
216208
}
217209
}

src/Renci.SshNet/Common/PipeStream.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public override void Write(byte[] buffer, int offset, int count)
9090
{
9191
lock (_sync)
9292
{
93-
ThrowIfDisposed();
93+
ThrowHelper.ThrowObjectDisposedIf(_disposed, this);
9494

9595
AssertValid();
9696

@@ -232,17 +232,5 @@ public override long Position
232232
get { return 0; }
233233
set { throw new NotSupportedException(); }
234234
}
235-
236-
private void ThrowIfDisposed()
237-
{
238-
#if NET7_0_OR_GREATER
239-
ObjectDisposedException.ThrowIf(_disposed, this);
240-
#else
241-
if (_disposed)
242-
{
243-
throw new ObjectDisposedException(GetType().FullName);
244-
}
245-
#endif // NET7_0_OR_GREATER
246-
}
247235
}
248236
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#nullable enable
2+
using System;
3+
4+
namespace Renci.SshNet.Common
5+
{
6+
internal static class ThrowHelper
7+
{
8+
public static void ThrowObjectDisposedIf(bool condition, object instance)
9+
{
10+
#if NET7_0_OR_GREATER
11+
ObjectDisposedException.ThrowIf(condition, instance);
12+
#else
13+
if (condition)
14+
{
15+
Throw(instance);
16+
17+
static void Throw(object? instance)
18+
{
19+
throw new ObjectDisposedException(instance?.GetType().FullName);
20+
}
21+
}
22+
#endif
23+
}
24+
}
25+
}

src/Renci.SshNet/ForwardedPortDynamic.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ protected override void StopPort(TimeSpan timeout)
128128
/// <exception cref="ObjectDisposedException">The current instance is disposed.</exception>
129129
protected override void CheckDisposed()
130130
{
131-
#if NET7_0_OR_GREATER
132-
ObjectDisposedException.ThrowIf(_isDisposed, this);
133-
#else
134-
if (_isDisposed)
135-
{
136-
throw new ObjectDisposedException(GetType().FullName);
137-
}
138-
#endif // NET7_0_OR_GREATER
131+
ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
139132
}
140133

141134
/// <summary>

src/Renci.SshNet/ForwardedPortLocal.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,7 @@ protected override void StopPort(TimeSpan timeout)
164164
/// <exception cref="ObjectDisposedException">The current instance is disposed.</exception>
165165
protected override void CheckDisposed()
166166
{
167-
#if NET7_0_OR_GREATER
168-
ObjectDisposedException.ThrowIf(_isDisposed, this);
169-
#else
170-
if (_isDisposed)
171-
{
172-
throw new ObjectDisposedException(GetType().FullName);
173-
}
174-
#endif // NET7_0_OR_GREATER
167+
ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
175168
}
176169

177170
/// <summary>

src/Renci.SshNet/ForwardedPortRemote.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,7 @@ protected override void StopPort(TimeSpan timeout)
228228
/// <exception cref="ObjectDisposedException">The current instance is disposed.</exception>
229229
protected override void CheckDisposed()
230230
{
231-
#if NET7_0_OR_GREATER
232-
ObjectDisposedException.ThrowIf(_isDisposed, this);
233-
#else
234-
if (_isDisposed)
235-
{
236-
throw new ObjectDisposedException(GetType().FullName);
237-
}
238-
#endif // NET7_0_OR_GREATER
231+
ThrowHelper.ThrowObjectDisposedIf(_isDisposed, this);
239232
}
240233

241234
private void Session_ChannelOpening(object sender, MessageEventArgs<ChannelOpenMessage> e)

src/Renci.SshNet/Renci.SshNet.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<AssemblyName>Renci.SshNet</AssemblyName>
55
<Product>SSH.NET</Product>
66
<AssemblyTitle>SSH.NET</AssemblyTitle>
7-
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
7+
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
88
</PropertyGroup>
99

1010
<PropertyGroup>

src/Renci.SshNet/Sftp/SftpFileReader.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@ public SftpFileReader(byte[] handle, ISftpSession sftpSession, uint chunkSize, i
7474

7575
public byte[] Read()
7676
{
77-
#if NET7_0_OR_GREATER
78-
ObjectDisposedException.ThrowIf(_disposingOrDisposed, this);
79-
#else
80-
if (_disposingOrDisposed)
81-
{
82-
throw new ObjectDisposedException(GetType().FullName);
83-
}
84-
#endif // NET7_0_OR_GREATER
77+
ThrowHelper.ThrowObjectDisposedIf(_disposingOrDisposed, this);
8578

8679
if (_exception is not null)
8780
{

src/Renci.SshNet/Sftp/SftpFileStream.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,14 +1364,7 @@ private void SetupWrite()
13641364

13651365
private void CheckSessionIsOpen()
13661366
{
1367-
#if NET7_0_OR_GREATER
1368-
ObjectDisposedException.ThrowIf(_session is null, this);
1369-
#else
1370-
if (_session is null)
1371-
{
1372-
throw new ObjectDisposedException(GetType().FullName);
1373-
}
1374-
#endif // NET7_0_OR_GREATER
1367+
ThrowHelper.ThrowObjectDisposedIf(_session is null, this);
13751368

13761369
if (!_session.IsOpen)
13771370
{

0 commit comments

Comments
 (0)