Skip to content

Commit f8925b3

Browse files
committed
clean code
1 parent d829217 commit f8925b3

File tree

93 files changed

+3051
-1354
lines changed

Some content is hidden

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

93 files changed

+3051
-1354
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
88
</PropertyGroup>
9-
9+
1010
<!--NuGet-->
1111
<PropertyGroup>
1212
<Authors>ManagedCode</Authors>

ManagedCode.Communication.Benchmark/CreateInstanceFailBenchmark.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Net;
12
using BenchmarkDotNet.Attributes;
23

34
namespace ManagedCode.Communication.Benchmark;
@@ -57,24 +58,24 @@ public Result ActivatorCreateInstanceGenericInt()
5758
[Benchmark]
5859
public Result CreateInstanceTypeError()
5960
{
60-
return Result.Fail("about:blank", "Error", System.Net.HttpStatusCode.BadRequest);
61+
return Result.Fail("about:blank", "Error", HttpStatusCode.BadRequest);
6162
}
6263

6364
[Benchmark]
6465
public Result<int> CreateInstanceTypeIntError()
6566
{
66-
return Result<int>.Fail("about:blank", "Error", System.Net.HttpStatusCode.BadRequest);
67+
return Result<int>.Fail("about:blank", "Error", HttpStatusCode.BadRequest);
6768
}
6869

6970
[Benchmark]
7071
public Result CreateInstanceTypeErrorInterface()
7172
{
72-
return Result.Fail("about:blank", "Error", System.Net.HttpStatusCode.BadRequest);
73+
return Result.Fail("about:blank", "Error", HttpStatusCode.BadRequest);
7374
}
7475

7576
[Benchmark]
7677
public Result<int> CreateInstanceTypeIntErrorInterface()
7778
{
78-
return Result<int>.Fail("about:blank", "Error", System.Net.HttpStatusCode.BadRequest);
79+
return Result<int>.Fail("about:blank", "Error", HttpStatusCode.BadRequest);
7980
}
8081
}

ManagedCode.Communication.Benchmark/ManagedCode.Communication.Benchmark.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
12+
<PackageReference Include="BenchmarkDotNet" Version="0.15.2"/>
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<ProjectReference Include="..\ManagedCode.Communication\ManagedCode.Communication.csproj" />
16+
<ProjectReference Include="..\ManagedCode.Communication\ManagedCode.Communication.csproj"/>
1717
</ItemGroup>
1818

1919
</Project>

ManagedCode.Communication.Benchmark/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ public class Program
77
{
88
public static void Main(string[] args)
99
{
10-
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args
10+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly)
11+
.Run(args
1112

1213
#if DEBUG
13-
, new DebugInProcessConfig()
14+
, new DebugInProcessConfig()
1415
#endif
15-
);
16+
);
1617
}
1718
}

ManagedCode.Communication.Benchmark/ResultCreationBenchmark.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Concurrent;
32
using System.Globalization;
43
using System.Net;
@@ -14,11 +13,11 @@ public class ResultCreationBenchmark
1413
private static readonly Exception TestException = new InvalidOperationException("Benchmark test");
1514
private static readonly Type ResultIntType = typeof(Result<int>);
1615
private static readonly ConcurrentDictionary<Type, MethodInfo> MethodCache = new();
17-
18-
private MethodInfo _cachedMethod = null!;
19-
private readonly object[] _exceptionArray = new object[1];
2016
private readonly Exception _exception = TestException;
21-
17+
private readonly object[] _exceptionArray = new object[1];
18+
19+
private MethodInfo _cachedMethod = null!;
20+
2221
[GlobalSetup]
2322
public void Setup()
2423
{
@@ -56,8 +55,7 @@ public object Reflection_CachedMethod_ReuseArray()
5655
[Benchmark]
5756
public object Reflection_ConcurrentDictionary()
5857
{
59-
var method = MethodCache.GetOrAdd(ResultIntType, type =>
60-
type.GetMethod(nameof(Result.Fail), [typeof(Exception), typeof(HttpStatusCode)])!);
58+
var method = MethodCache.GetOrAdd(ResultIntType, type => type.GetMethod(nameof(Result.Fail), [typeof(Exception), typeof(HttpStatusCode)])!);
6159
return method.Invoke(null, [TestException, HttpStatusCode.InternalServerError])!;
6260
}
6361

@@ -67,15 +65,13 @@ public object Activator_TryCreateInstance()
6765
var result = Activator.CreateInstance(ResultIntType);
6866
return result!;
6967
}
70-
68+
7169
[Benchmark]
7270
public object Activator_WithPropertySet()
7371
{
74-
var resultType = Activator.CreateInstance(ResultIntType,
75-
BindingFlags.NonPublic | BindingFlags.Instance,
76-
null, [TestException],
72+
var resultType = Activator.CreateInstance(ResultIntType, BindingFlags.NonPublic | BindingFlags.Instance, null, [TestException],
7773
CultureInfo.CurrentCulture);
78-
74+
7975
return resultType!;
8076
}
8177
}
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,74 @@
11
namespace ManagedCode.Communication.Extensions.Constants;
22

33
/// <summary>
4-
/// Constants for Problem details to avoid string literals throughout the codebase.
4+
/// Constants for Problem details to avoid string literals throughout the codebase.
55
/// </summary>
66
public static class ProblemConstants
77
{
88
/// <summary>
9-
/// Problem titles
9+
/// Problem titles
1010
/// </summary>
1111
public static class Titles
1212
{
1313
/// <summary>
14-
/// Title for validation failure problems
14+
/// Title for validation failure problems
1515
/// </summary>
1616
public const string ValidationFailed = "Validation failed";
17-
17+
1818
/// <summary>
19-
/// Title for unexpected error problems
19+
/// Title for unexpected error problems
2020
/// </summary>
2121
public const string UnexpectedError = "An unexpected error occurred";
2222
}
23-
23+
2424
/// <summary>
25-
/// Problem extension keys
25+
/// Problem extension keys
2626
/// </summary>
2727
public static class ExtensionKeys
2828
{
2929
/// <summary>
30-
/// Key for validation errors in problem extensions
30+
/// Key for validation errors in problem extensions
3131
/// </summary>
3232
public const string ValidationErrors = "validationErrors";
33-
33+
3434
/// <summary>
35-
/// Key for trace ID in problem extensions
35+
/// Key for trace ID in problem extensions
3636
/// </summary>
3737
public const string TraceId = "traceId";
38-
38+
3939
/// <summary>
40-
/// Key for hub method name in problem extensions
40+
/// Key for hub method name in problem extensions
4141
/// </summary>
4242
public const string HubMethod = "hubMethod";
43-
43+
4444
/// <summary>
45-
/// Key for hub type name in problem extensions
45+
/// Key for hub type name in problem extensions
4646
/// </summary>
4747
public const string HubType = "hubType";
48-
48+
4949
/// <summary>
50-
/// Key for inner exception in problem extensions
50+
/// Key for inner exception in problem extensions
5151
/// </summary>
5252
public const string InnerException = "innerException";
53-
53+
5454
/// <summary>
55-
/// Key for stack trace in problem extensions
55+
/// Key for stack trace in problem extensions
5656
/// </summary>
5757
public const string StackTrace = "stackTrace";
58-
58+
5959
/// <summary>
60-
/// Key for error type (enum type name) in problem extensions
60+
/// Key for error type (enum type name) in problem extensions
6161
/// </summary>
6262
public const string ErrorType = "errorType";
63-
63+
6464
/// <summary>
65-
/// Key for error code name (enum value name) in problem extensions
65+
/// Key for error code name (enum value name) in problem extensions
6666
/// </summary>
6767
public const string ErrorCodeName = "errorCodeName";
68-
68+
6969
/// <summary>
70-
/// Key for error code value (enum numeric value) in problem extensions
70+
/// Key for error code value (enum numeric value) in problem extensions
7171
/// </summary>
7272
public const string ErrorCodeValue = "errorCodeValue";
7373
}
74-
}
74+
}

ManagedCode.Communication.Extensions/Extensions/CommunicationAppBuilderExtensions.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using System;
22
using Microsoft.AspNetCore.Builder;
3-
using Microsoft.AspNetCore.Mvc;
4-
using Microsoft.Extensions.DependencyInjection;
5-
using Microsoft.Extensions.Options;
6-
using ManagedCode.Communication.Extensions;
73

84
namespace ManagedCode.Communication.Extensions.Extensions;
95

@@ -12,7 +8,9 @@ public static class CommunicationAppBuilderExtensions
128
public static IApplicationBuilder UseCommunication(this IApplicationBuilder app)
139
{
1410
if (app == null)
11+
{
1512
throw new ArgumentNullException(nameof(app));
13+
}
1614

1715
return app;
1816
}

ManagedCode.Communication.Extensions/Extensions/ControllerExtensions.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ namespace ManagedCode.Communication.Extensions.Extensions;
55

66
public static class ControllerExtensions
77
{
8-
public static IActionResult ToActionResult<T>(this ManagedCode.Communication.Result<T> result)
8+
public static IActionResult ToActionResult<T>(this Result<T> result)
99
{
10-
return result.IsSuccess
11-
? new OkObjectResult(result.Value)
12-
: new BadRequestObjectResult(result.Problem?.Detail ?? "Operation failed");
10+
return result.IsSuccess ? new OkObjectResult(result.Value) : new BadRequestObjectResult(result.Problem?.Detail ?? "Operation failed");
1311
}
1412

15-
public static Microsoft.AspNetCore.Http.IResult ToHttpResult<T>(this ManagedCode.Communication.Result<T> result)
13+
public static Microsoft.AspNetCore.Http.IResult ToHttpResult<T>(this Result<T> result)
1614
{
1715
return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Problem?.Detail ?? "Operation failed");
1816
}

ManagedCode.Communication.Extensions/Extensions/HubOptionsExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
2+
using ManagedCode.Communication.Extensions.Filters;
23
using Microsoft.AspNetCore.SignalR;
34
using Microsoft.Extensions.DependencyInjection;
4-
using ManagedCode.Communication.Extensions;
5-
using ManagedCode.Communication.Extensions.Filters;
65

76
namespace ManagedCode.Communication.Extensions.Extensions;
87

ManagedCode.Communication.Extensions/Extensions/ServiceCollectionExtensions.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212

1313
namespace ManagedCode.Communication.Extensions.Extensions;
1414

15-
1615
public static class HostApplicationBuilderExtensions
1716
{
1817
public static IHostApplicationBuilder AddCommunication(this IHostApplicationBuilder builder)
1918
{
2019
builder.Services.AddCommunication(options => options.ShowErrorDetails = builder.Environment.IsDevelopment());
2120
return builder;
2221
}
23-
22+
2423
public static IHostApplicationBuilder AddCommunication(this IHostApplicationBuilder builder, Action<CommunicationOptions> config)
2524
{
2625
builder.Services.AddCommunication(config);
@@ -30,16 +29,16 @@ public static IHostApplicationBuilder AddCommunication(this IHostApplicationBuil
3029

3130
public static class ServiceCollectionExtensions
3231
{
33-
3432
public static IServiceCollection AddCommunication(this IServiceCollection services, Action<CommunicationOptions>? configure = null)
3533
{
3634
if (configure != null)
35+
{
3736
services.Configure(configure);
37+
}
3838

3939
return services;
4040
}
41-
42-
41+
4342

4443
public static IServiceCollection AddDefaultProblemDetails(this IServiceCollection services)
4544
{
@@ -68,20 +67,20 @@ public static IServiceCollection AddCommunicationFilters(this IServiceCollection
6867

6968
return services;
7069
}
71-
70+
7271
public static MvcOptions AddCommunicationFilters(this MvcOptions options)
7372
{
7473
options.Filters.Add<CommunicationExceptionFilter>();
7574
options.Filters.Add<CommunicationModelValidationFilter>();
7675
options.Filters.Add<ResultToActionResultFilter>();
77-
76+
7877
return options;
7978
}
80-
79+
8180
public static HubOptions AddCommunicationFilters(this HubOptions options)
8281
{
8382
options.AddFilter<CommunicationHubExceptionFilter>();
84-
83+
8584
return options;
8685
}
8786
}

0 commit comments

Comments
 (0)