Skip to content

Commit 12044d5

Browse files
authored
Merge pull request #1129 from drewnoakes/review-conditional-code
Review conditional code
2 parents 2c17a24 + d5c724e commit 12044d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+67
-346
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<LangVersion>10</LangVersion>
4+
<LangVersion>13</LangVersion>
55
<Nullable>enable</Nullable>
66
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
77
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>

src/NetMQ.Tests/ClientServer.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ public async Task AsyncWithCancellationToken()
8282
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await server.ReceiveStringAsync(source.Token));
8383
}
8484

85-
#if NETCOREAPP3_1
86-
85+
#if NETSTANDARD || NET
8786
[Fact(Timeout = 120)]
88-
public async void AsyncEnumerableCanceled()
87+
public async Task AsyncEnumerableCanceled()
8988
{
9089
using CancellationTokenSource source = new CancellationTokenSource();
9190
using var server = new ServerSocket();
@@ -100,7 +99,7 @@ await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
10099
}
101100

102101
[Fact(Timeout = 1000)]
103-
public void AsyncEnumerable()
102+
public async Task AsyncEnumerable()
104103
{
105104
using var server = new ServerSocket();
106105
int port = server.BindRandomPort("tcp://*");
@@ -152,12 +151,10 @@ public void AsyncEnumerable()
152151
client.Send("1");
153152
client.Send("1");
154153

155-
t1.Wait();
156-
t2.Wait();
154+
await Task.WhenAll(t1, t2);
157155

158156
Assert.Equal(15002, totalCount);
159157
}
160-
161158
#endif
162159
}
163160
}

src/NetMQ.Tests/NetMQPollerTest.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
24
using System.Diagnostics;
35
using System.Net;
46
using System.Net.Sockets;
@@ -8,11 +10,6 @@
810
using NetMQ.Sockets;
911
using Xunit;
1012

11-
#if !NET35
12-
using System.Collections.Concurrent;
13-
using System.Collections.Generic;
14-
#endif
15-
1613
// ReSharper disable AccessToDisposedClosure
1714

1815
namespace NetMQ.Tests
@@ -864,7 +861,6 @@ public void NativeSocket()
864861

865862
#region TaskScheduler tests
866863

867-
#if !NET35
868864
[Fact]
869865
public async Task OneTask()
870866
{
@@ -989,13 +985,11 @@ public async Task TwoThreads()
989985
Assert.Equal(100, count2);
990986
}
991987
}
992-
#endif
993988

994989
#endregion
995990

996991
#region ISynchronizeInvoke tests
997992

998-
#if NET451
999993
[Fact]
1000994
public void ISynchronizeInvokeWorks()
1001995
{
@@ -1017,8 +1011,7 @@ public void ISynchronizeInvokeWorks()
10171011
Assert.True(isCorrectThread);
10181012
}
10191013
}
1020-
#endif
10211014

1022-
#endregion
1015+
#endregion
10231016
}
10241017
}

src/NetMQ.Tests/NetMQQueueTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#if !NET35
2-
using System;
3-
using System.Net.Sockets;
1+
using System;
42
using System.Threading;
53
using System.Threading.Tasks;
64
using NetMQ.Sockets;
@@ -81,4 +79,3 @@ public void WithPoller()
8179
}
8280
}
8381
}
84-
#endif

src/NetMQ.Tests/RequestWithRetryTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if !NET35
2-
using System;
1+
using System;
32
using System.Diagnostics;
43
using NetMQ.Sockets;
54
using Xunit;
@@ -205,4 +204,3 @@ public void RequestResponseStringWithRetrySucceedsNotOnFirstTry()
205204
}
206205
}
207206
}
208-
#endif

src/NetMQ.Tests/ThrowingTraceListener.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Diagnostics;
3-
using System.Runtime.Serialization;
43

54
namespace NetMQ.Tests
65
{
@@ -19,7 +18,6 @@ public override void WriteLine(string? message)
1918
{
2019
}
2120

22-
[Serializable]
2321
public class DebugAssertFailureException : Exception
2422
{
2523
public DebugAssertFailureException()
@@ -33,10 +31,6 @@ public DebugAssertFailureException(string message) : base(message)
3331
public DebugAssertFailureException(string message, Exception inner) : base(message, inner)
3432
{
3533
}
36-
37-
protected DebugAssertFailureException(SerializationInfo info, StreamingContext context) : base(info, context)
38-
{
39-
}
4034
}
4135
}
4236
}

src/NetMQ/Core/Mailbox.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
using System;
2322
using System.Diagnostics;
2423
using System.Net.Sockets;
2524
using NetMQ.Core.Utils;

src/NetMQ/Core/Mechanisms/CurveClientMechanism.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics;
32
using System.Security.Cryptography;
43
using System.Text;
54
using NaCl;

src/NetMQ/Core/Mechanisms/CurveServerMechanism.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using System.Linq;
32
using System.Security.Cryptography;
4-
using System.Text;
53
using NaCl;
64
using NetMQ.Core.Utils;
75

src/NetMQ/Core/Mechanisms/Mechanism.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43
using System.Text;
54
using NetMQ.Core.Utils;
@@ -191,7 +190,7 @@ protected void AddBasicProperties(Span<byte> output)
191190
}
192191
else
193192
{
194-
written = AddProperty(output, ZmtpPropertyIdentity, new byte[0]);
193+
written = AddProperty(output, ZmtpPropertyIdentity, []);
195194
output = output.Slice(written);
196195
}
197196
}

src/NetMQ/Core/Mechanisms/NullMechanism.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Text;
32
using NetMQ.Core.Utils;
43

54
namespace NetMQ.Core.Mechanisms

src/NetMQ/Core/Patterns/Client.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics;
21
using NetMQ.Core.Patterns.Utils;
32

43
namespace NetMQ.Core.Patterns

src/NetMQ/Core/Patterns/Dealer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
using System.Diagnostics;
2322
using NetMQ.Core.Patterns.Utils;
2423

2524
namespace NetMQ.Core.Patterns

src/NetMQ/Core/Patterns/Gather.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics;
21
using NetMQ.Core.Patterns.Utils;
32

43
namespace NetMQ.Core.Patterns

src/NetMQ/Core/Patterns/Pair.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
using System.Diagnostics;
23-
2422
namespace NetMQ.Core.Patterns
2523
{
2624
internal sealed class Pair : SocketBase

src/NetMQ/Core/Patterns/Peer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ You should have received a copy of the GNU Lesser General Public License
2323
using System;
2424
using System.Collections.Generic;
2525
using System.Diagnostics;
26-
using System.Threading;
2726
using NetMQ.Core.Patterns.Utils;
28-
using NetMQ.Core.Utils;
2927

3028
namespace NetMQ.Core.Patterns
3129
{

src/NetMQ/Core/Patterns/Pull.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
using System.Diagnostics;
2322
using NetMQ.Core.Patterns.Utils;
2423

2524
namespace NetMQ.Core.Patterns

src/NetMQ/Core/Patterns/Push.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ You should have received a copy of the GNU Lesser General Public License
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22-
using System.Diagnostics;
2322
using NetMQ.Core.Patterns.Utils;
2423

2524
namespace NetMQ.Core.Patterns

src/NetMQ/Core/Patterns/Radio.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.Linq;
54
using System.Text;
65
using NetMQ.Core.Patterns.Utils;

src/NetMQ/Core/Patterns/Scatter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Diagnostics;
21
using NetMQ.Core.Patterns.Utils;
32

43
namespace NetMQ.Core.Patterns

src/NetMQ/Core/Patterns/Utils/LoadBalancer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ You should have received a copy of the GNU Lesser General Public License
2222

2323
using System.Collections.Generic;
2424
using System.Diagnostics;
25-
using System.Diagnostics.CodeAnalysis;
2625

2726
namespace NetMQ.Core.Patterns.Utils
2827
{

src/NetMQ/Core/Patterns/Utils/MultiTrie.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private bool AddHelper(Span<byte> prefix, [NotNull] Pipe pipe)
149149
/// <returns></returns>
150150
public bool RemoveHelper([NotNull] Pipe pipe, [NotNull] MultiTrieDelegate func, [CanBeNull] object arg)
151151
{
152-
return RemoveHelper(pipe, EmptyArray<byte>.Instance, 0, 0, func, arg);
152+
return RemoveHelper(pipe, [], 0, 0, func, arg);
153153
}
154154

155155
private bool RemoveHelper([NotNull] Pipe pipe, [NotNull] byte[] buffer, int bufferSize, int maxBufferSize, [NotNull] MultiTrieDelegate func, [CanBeNull] object arg)

src/NetMQ/Core/Patterns/XPub.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ You should have received a copy of the GNU Lesser General Public License
2121

2222
using System;
2323
using System.Collections.Generic;
24-
using System.Diagnostics;
2524
using System.Text;
2625
using NetMQ.Core.Patterns.Utils;
2726

src/NetMQ/Core/Transports/DecoderBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ You should have received a copy of the GNU Lesser General Public License
2020
*/
2121

2222
using System;
23-
using System.Diagnostics;
2423

2524
namespace NetMQ.Core.Transports
2625
{

src/NetMQ/Core/Transports/EncoderBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected EncoderBase(int bufferSize, Endianness endian)
6969
public void Dispose()
7070
{
7171
if (m_inProgress.IsInitialised)
72-
m_inProgress.Close();
72+
m_inProgress.Close();
7373
}
7474

7575
/// <summary>
@@ -141,7 +141,7 @@ public int Encode(ref ByteArraySegment? data, int size)
141141
return pos;
142142
}
143143

144-
public void LoadMsg (ref Msg msg)
144+
public void LoadMsg(ref Msg msg)
145145
{
146146
m_inProgress = msg;
147147
m_hasMessage = true;

src/NetMQ/Core/Transports/RawDecoder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics;
32

43
namespace NetMQ.Core.Transports
54
{

src/NetMQ/Core/Transports/StreamEngine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ You should have received a copy of the GNU Lesser General Public License
2929
using AsyncIO;
3030
using JetBrains.Annotations;
3131
using NetMQ.Core.Mechanisms;
32-
using NetMQ.Core.Patterns;
3332
using NetMQ.Core.Utils;
3433

3534
namespace NetMQ.Core.Transports

src/NetMQ/Core/Utils/Signaler.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,14 @@ public void Close()
7272

7373
try
7474
{
75-
#if NET35
76-
m_writeSocket.Close();
77-
#else
7875
m_writeSocket.Dispose();
79-
#endif
8076
}
8177
catch (SocketException)
8278
{}
8379

8480
try
8581
{
86-
#if NET35
87-
m_readSocket.Close();
88-
#else
8982
m_readSocket.Dispose();
90-
#endif
9183
}
9284
catch (SocketException)
9385
{}

src/NetMQ/Core/Utils/SocketUtility.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ internal static class SocketUtility
4747
/// <exception cref="SocketException">an error occurred when attempting to access the socket.</exception>
4848
public static void Select(IList? checkRead, IList? checkWrite, IList? checkError, int microSeconds)
4949
{
50-
#if NET35
51-
// .NET 3.5 has a bug, such that -1 is not blocking the select call - therefore we use here instead the maximum integer value.
52-
if (microSeconds == -1)
53-
microSeconds = int.MaxValue;
54-
#endif
55-
5650
Socket.Select(checkRead, checkWrite, checkError, microSeconds);
5751
}
5852
}

src/NetMQ/Core/Utils/StringLib.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static string AsString(this Socket socket)
110110
{
111111
sb.Append("IsBound,");
112112
}
113-
if (socket.LingerState.Enabled)
113+
if (socket.LingerState?.Enabled == true)
114114
{
115115
sb.Append("LingerTime=");
116116
sb.Append(socket.LingerState.LingerTime);

src/NetMQ/Core/Utils/Switch.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading;
1+
using System.Threading;
32

43
namespace NetMQ.Core.Utils
54
{

src/NetMQ/Core/ZmqSocketOption.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
3-
namespace NetMQ.Core
1+
namespace NetMQ.Core
42
{
53
/// <summary>
64
/// This enum-type serves to identity a particular socket-option.

src/NetMQ/DnsEndPoint.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)