Skip to content

Commit

Permalink
Apply code analyzer suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
menees committed Oct 13, 2024
1 parent 641dc41 commit 6fdd0aa
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Menees.Remoting/Json/ReadOnlyDictionaryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private class ReadOnlyDictionaryConverterInner<TKey, TValue> : JsonConverter<IRe
typeToConvert,
BindingFlags.Instance | BindingFlags.Public,
binder: null,
args: new object[] { dictionary },
args: [dictionary],
culture: null);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Menees.Remoting/MessageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async Task<TOut> SendAsync(TIn message, CancellationToken cancellationTok
{
Request request = new()
{
Arguments = new() { new UserSerializedValue(typeof(TIn), message, this.UserSerializer) },
Arguments = [new UserSerializedValue(typeof(TIn), message, this.UserSerializer)],
};

Response? response = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Menees.Remoting/Models/ServiceError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ private Exception CreateException()
// Try to throw a new exception of the requested type. The new exception's StackTrace will be from the client,
// but its message, data type, and inner exception will match the server's exception info.
Exception result;
ConstructorInfo? constructor = this.ExceptionType.GetConstructor(new[] { typeof(string), typeof(Exception) });
ConstructorInfo? constructor = this.ExceptionType.GetConstructor([typeof(string), typeof(Exception)]);
if (constructor != null)
{
result = (Exception)constructor.Invoke(new object?[] { this.Message, innerException });
result = (Exception)constructor.Invoke([this.Message, innerException]);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Menees.Remoting/Pipes/PipeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class PipeClient : PipeNode
#region Private Data Members

#pragma warning disable SA1310 // Field names should not contain underscore. Named like WinError.h constant.
private const int ERROR_SEM_TIMEOUT = unchecked((int)0x80070079);
private const int ERROR_SEM_TIMEOUT = unchecked((int)0x80_07_00_79);
#pragma warning restore SA1310 // Field names should not contain underscore

private readonly PipeClientSecurity? security;
Expand Down
2 changes: 1 addition & 1 deletion src/Menees.Remoting/Pipes/PipeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class PipeServer : PipeNode
{
#region Private Data Members

private readonly HashSet<PipeServerListener> listeners = new();
private readonly HashSet<PipeServerListener> listeners = [];
private readonly int minListeners;
private readonly int maxListeners;
private readonly IServer server;
Expand Down
2 changes: 1 addition & 1 deletion src/Menees.Remoting/RmiServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected override void Dispose(bool disposing)

private static Dictionary<string, MethodInfo> CreateMethodSignatureDictionary()
{
List<(string Signature, MethodInfo Method)> items = new();
List<(string Signature, MethodInfo Method)> items = [];

void AddMethods(Type interfaceType)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Menees.Remoting/ServerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class ServerHost : IServerHost, IDisposable
#region Private Data Members

private readonly ManualResetEventSlim resetEvent = new(false);
private readonly HashSet<IServer> servers = new();
private readonly HashSet<IServer> servers = [];
private bool isDisposed;
private bool isExiting;

Expand Down
16 changes: 9 additions & 7 deletions tests/Menees.Remoting.Tests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ private protected static void TestProxy(ITester testerProxy, int testId, bool is
Widget paper = testerProxy.CreateWidget("Paper", 0.01m, 85, 110);
paper.Name.ShouldBe("Paper");
paper.Cost.ShouldBe(0.01m);
paper.Dimensions.ShouldBe(new[] { 85, 110 });
paper.Dimensions.ShouldBe([85, 110]);

paper = testerProxy.UpdateWidget(paper, "Fancy Paper", 0.02m, null);
paper.Name.ShouldBe("Fancy Paper");
paper.Cost.ShouldBe(0.02m);
paper.Dimensions.ShouldBe(new[] { 85, 110 });
paper.Dimensions.ShouldBe([85, 110]);
}

private protected static void WriteUnhandledServerException(Exception ex)
Expand All @@ -168,12 +168,14 @@ private static void InitializeProcessStartInfo(Type hostProgram, out ProcessStar
{
string hostExeLocation = hostProgram.Assembly.Location;

startInfo = new();
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.ErrorDialog = false;
startInfo = new()
{
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false,
};

arguments = new();
arguments = [];
if (string.Equals(Path.GetExtension(hostExeLocation), ".exe", StringComparison.OrdinalIgnoreCase))
{
startInfo.FileName = Path.GetFileName(hostExeLocation);
Expand Down
2 changes: 1 addition & 1 deletion tests/Menees.Remoting.Tests/MessageNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task Base64ExampleAsync()
server.Start();

using MessageClient<byte[], string> client = new(ServerPath);
string response = await client.SendAsync(new byte[] { 1, 2, 3, 4 }).ConfigureAwait(false);
string response = await client.SendAsync([1, 2, 3, 4]).ConfigureAwait(false);
response.ShouldBe("AQIDBA==");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Menees.Remoting.Tests/RmiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void HasherExample()
using RmiClient<IHasher> client = new(ServerPath);
IHasher proxy = client.CreateProxy();

proxy.Hash(new byte[] { 1, 2, 3, 4 }).Length.ShouldBe(20);
proxy.Hash([1, 2, 3, 4]).Length.ShouldBe(20);
proxy.Hash("Testing").ShouldBe("0820b32b206b7352858e8903a838ed14319acdfd");
}

Expand Down

0 comments on commit 6fdd0aa

Please sign in to comment.