Skip to content

Commit 6aa0d7f

Browse files
authored
Merge pull request #20 from dotarj/refactor-enable-stylecop
enable stylecop and refactoring
2 parents 8874712 + a2fb097 commit 6aa0d7f

21 files changed

Lines changed: 283 additions & 202 deletions

PartialResponse.sln

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

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26730.16
4+
VisualStudioVersion = 15.0.27130.2010
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{76236DA2-0225-4CA2-A2C8-46C665DE6D71}"
77
EndProject

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/ControllerExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Microsoft.AspNetCore.Mvc
77
{
8+
/// <summary>
9+
/// Provides extension methods for the <see cref="ControllerBase"/> class.
10+
/// </summary>
811
public static class ControllerExtensions
912
{
1013
/// <summary>

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcPartialJsonMvcBuilderExtensions.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111

1212
namespace PartialResponse.Extensions.DependencyInjection
1313
{
14+
/// <summary>
15+
/// Provides extension methods for the <see cref="IMvcBuilder"/> interface.
16+
/// </summary>
1417
public static class MvcPartialJsonMvcBuilderExtensions
1518
{
19+
/// <summary>
20+
/// Adds services to the <see cref="IServiceCollection"/>.
21+
/// </summary>
22+
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
23+
/// <returns>A reference to the current instance of <see cref="IMvcBuilder"/>.</returns>
1624
public static IMvcBuilder AddPartialJsonFormatters(this IMvcBuilder builder)
1725
{
1826
if (builder == null)
@@ -21,12 +29,18 @@ public static IMvcBuilder AddPartialJsonFormatters(this IMvcBuilder builder)
2129
}
2230

2331
AddPartialJsonFormatterServices(builder.Services);
32+
2433
return builder;
2534
}
2635

27-
public static IMvcBuilder AddPartialJsonFormatters(
28-
this IMvcBuilder builder,
29-
Action<JsonSerializerSettings> setupAction)
36+
/// <summary>
37+
/// Adds services to the <see cref="IServiceCollection"/> and the <paramref name="setupAction"/> to configure
38+
/// the <see cref="JsonSerializerSettings"/>.
39+
/// </summary>
40+
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
41+
/// <param name="setupAction">An action to configure the <see cref="JsonSerializerSettings"/>.</param>
42+
/// <returns>A reference to the current instance of <see cref="IMvcBuilder"/>.</returns>
43+
public static IMvcBuilder AddPartialJsonFormatters(this IMvcBuilder builder, Action<JsonSerializerSettings> setupAction)
3044
{
3145
if (builder == null)
3246
{
@@ -46,14 +60,12 @@ public static IMvcBuilder AddPartialJsonFormatters(
4660
}
4761

4862
/// <summary>
49-
/// Adds configuration of <see cref="MvcPartialJsonOptions"/> for the application.
63+
/// Adds the <paramref name="setupAction"/> to configure the <see cref="JsonSerializerSettings"/>.
5064
/// </summary>
5165
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
52-
/// <param name="setupAction">The <see cref="MvcPartialJsonOptions"/> which need to be configured.</param>
53-
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
54-
public static IMvcBuilder AddPartialJsonOptions(
55-
this IMvcBuilder builder,
56-
Action<MvcPartialJsonOptions> setupAction)
66+
/// <param name="setupAction">An action to configure the <see cref="MvcPartialJsonOptions"/>.</param>
67+
/// <returns>A reference to the current instance of <see cref="IMvcBuilder"/>.</returns>
68+
public static IMvcBuilder AddPartialJsonOptions(this IMvcBuilder builder, Action<MvcPartialJsonOptions> setupAction)
5769
{
5870
if (builder == null)
5971
{
@@ -66,14 +78,14 @@ public static IMvcBuilder AddPartialJsonOptions(
6678
}
6779

6880
builder.Services.Configure<MvcPartialJsonOptions>(setupAction);
81+
6982
return builder;
7083
}
7184

7285
// Internal for testing.
7386
internal static void AddPartialJsonFormatterServices(IServiceCollection services)
7487
{
75-
services.TryAddEnumerable(
76-
ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, MvcPartialJsonMvcOptionsSetup>());
88+
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, MvcPartialJsonMvcOptionsSetup>());
7789
services.TryAddSingleton<PartialJsonResultExecutor>();
7890
}
7991
}

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcPartialJsonMvcCoreBuilderExtensions.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111

1212
namespace PartialResponse.Extensions.DependencyInjection
1313
{
14+
/// <summary>
15+
/// Provides extension methods for the <see cref="IMvcCoreBuilder"/> interface.
16+
/// </summary>
1417
public static class MvcPartialJsonMvcCoreBuilderExtensions
1518
{
19+
/// <summary>
20+
/// Adds services to the <see cref="IServiceCollection"/>.
21+
/// </summary>
22+
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
23+
/// <returns>A reference to the current instance of <see cref="IMvcCoreBuilder"/>.</returns>
1624
public static IMvcCoreBuilder AddPartialJsonFormatters(this IMvcCoreBuilder builder)
1725
{
1826
if (builder == null)
@@ -21,12 +29,18 @@ public static IMvcCoreBuilder AddPartialJsonFormatters(this IMvcCoreBuilder buil
2129
}
2230

2331
AddPartialJsonFormatterServices(builder.Services);
32+
2433
return builder;
2534
}
2635

27-
public static IMvcCoreBuilder AddPartialJsonFormatters(
28-
this IMvcCoreBuilder builder,
29-
Action<JsonSerializerSettings> setupAction)
36+
/// <summary>
37+
/// Adds services to the <see cref="IServiceCollection"/> and the <paramref name="setupAction"/> to configure
38+
/// the <see cref="JsonSerializerSettings"/>.
39+
/// </summary>
40+
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
41+
/// <param name="setupAction">An action to configure the <see cref="JsonSerializerSettings"/>.</param>
42+
/// <returns>A reference to the current instance of <see cref="IMvcCoreBuilder"/>.</returns>
43+
public static IMvcCoreBuilder AddPartialJsonFormatters(this IMvcCoreBuilder builder, Action<JsonSerializerSettings> setupAction)
3044
{
3145
if (builder == null)
3246
{
@@ -46,14 +60,12 @@ public static IMvcCoreBuilder AddPartialJsonFormatters(
4660
}
4761

4862
/// <summary>
49-
/// Adds configuration of <see cref="MvcPartialJsonOptions"/> for the application.
63+
/// Adds the <paramref name="setupAction"/> to configure the <see cref="JsonSerializerSettings"/>.
5064
/// </summary>
5165
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
52-
/// <param name="setupAction">The <see cref="MvcPartialJsonOptions"/> which need to be configured.</param>
53-
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
54-
public static IMvcCoreBuilder AddPartialJsonOptions(
55-
this IMvcCoreBuilder builder,
56-
Action<MvcPartialJsonOptions> setupAction)
66+
/// <param name="setupAction">An action to configure the <see cref="MvcPartialJsonOptions"/>.</param>
67+
/// <returns>A reference to the current instance of <see cref="IMvcCoreBuilder"/>.</returns>
68+
public static IMvcCoreBuilder AddPartialJsonOptions(this IMvcCoreBuilder builder, Action<MvcPartialJsonOptions> setupAction)
5769
{
5870
if (builder == null)
5971
{
@@ -66,14 +78,14 @@ public static IMvcCoreBuilder AddPartialJsonOptions(
6678
}
6779

6880
builder.Services.Configure<MvcPartialJsonOptions>(setupAction);
81+
6982
return builder;
7083
}
7184

7285
// Internal for testing.
7386
internal static void AddPartialJsonFormatterServices(IServiceCollection services)
7487
{
75-
services.TryAddEnumerable(
76-
ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, MvcPartialJsonMvcOptionsSetup>());
88+
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, MvcPartialJsonMvcOptionsSetup>());
7789
services.TryAddSingleton<PartialJsonResultExecutor>();
7890
}
7991
}

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/HttpRequestExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Microsoft.AspNetCore.Http
88
{
9+
/// <summary>
10+
/// Provides extension methods for the <see cref="HttpRequest"/> class.
11+
/// </summary>
912
public static class HttpRequestExtensions
1013
{
1114
/// <summary>

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/Internal/JsonArrayPool.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,51 @@
66

77
namespace PartialResponse.AspNetCore.Mvc.Formatters.Json.Internal
88
{
9+
/// <summary>
10+
/// Provides a resource pool that enables reusing instances of type T[].
11+
/// </summary>
12+
/// <typeparam name="T">The type of the objects that are in the resource pool.</typeparam>
913
public class JsonArrayPool<T> : IArrayPool<T>
1014
{
11-
private readonly ArrayPool<T> _inner;
15+
private readonly ArrayPool<T> inner;
1216

17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="JsonArrayPool{T}"/> class.
19+
/// </summary>
20+
/// <param name="inner">The inner resource pool.</param>
1321
public JsonArrayPool(ArrayPool<T> inner)
1422
{
1523
if (inner == null)
1624
{
1725
throw new ArgumentNullException(nameof(inner));
1826
}
1927

20-
_inner = inner;
28+
this.inner = inner;
2129
}
2230

31+
/// <summary>
32+
/// Retrieves a buffer that is at least the requested length.
33+
/// </summary>
34+
/// <param name="minimumLength">The minimum length of the array.</param>
35+
/// <returns>An array of type T[] that is at least minimumLength in length.</returns>
2336
public T[] Rent(int minimumLength)
2437
{
25-
return _inner.Rent(minimumLength);
38+
return this.inner.Rent(minimumLength);
2639
}
2740

41+
/// <summary>
42+
/// Returns an array to the pool that was previously obtained using the Rent method on the same
43+
/// <see cref="ArrayPool{T}"/> instance.
44+
/// </summary>
45+
/// <param name="array">A buffer to return to the pool that was previously obtained using the Rent method.</param>
2846
public void Return(T[] array)
2947
{
3048
if (array == null)
3149
{
3250
throw new ArgumentNullException(nameof(array));
3351
}
3452

35-
_inner.Return(array);
53+
this.inner.Return(array);
3654
}
3755
}
3856
}

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/Internal/JsonSerializerExtensions.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Arjen Post. See License.txt and Notice.txt in the project root for license information.
22

3-
using Newtonsoft.Json;
4-
using Newtonsoft.Json.Linq;
53
using System;
64
using System.Linq;
5+
using Newtonsoft.Json;
6+
using Newtonsoft.Json.Linq;
77

88
namespace PartialResponse.AspNetCore.Mvc.Formatters.Json.Internal
99
{
@@ -15,14 +15,14 @@ namespace PartialResponse.AspNetCore.Mvc.Formatters.Json.Internal
1515
public static class JsonSerializerExtensions
1616
{
1717
/// <summary>
18-
/// Serializes the specified <see cref="Object"/> and writes the JSON structure
18+
/// Serializes the specified <see cref="object"/> and writes the JSON structure
1919
/// using the specified <see cref="JsonWriter"/>.
2020
/// </summary>
21-
/// <param name="jsonSerializer">The <see cref="JsonSerializer"/> used to serialize the specified <see cref="Object"/>.</param>
21+
/// <param name="jsonSerializer">The <see cref="JsonSerializer"/> used to serialize the specified <see cref="object"/>.</param>
2222
/// <param name="jsonWriter">The <see cref="JsonWriter"/> used to write the JSON structure.</param>
23-
/// <param name="value">The <see cref="Object"/> to serialize.</param>
23+
/// <param name="value">The <see cref="object"/> to serialize.</param>
2424
/// <param name="shouldSerialize">A <see cref="Func{T, TResult}"/> that is called for every field in the
25-
/// <see cref="Object"/> to serialize, indicating whether the field should be serialized.</param>
25+
/// <see cref="object"/> to serialize, indicating whether the field should be serialized.</param>
2626
public static void Serialize(this JsonSerializer jsonSerializer, JsonWriter jsonWriter, object value, Func<string, bool> shouldSerialize)
2727
{
2828
if (value == null)
@@ -147,7 +147,7 @@ private static string CombinePath(string path, string name)
147147
return name;
148148
}
149149

150-
return string.Format("{0}/{1}", path, name);
150+
return $"{path}/{name}";
151151
}
152152
}
153153
}

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/Internal/MediaTypeHeaderValues.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ namespace PartialResponse.AspNetCore.Mvc.Formatters.Json.Internal
66
{
77
internal class MediaTypeHeaderValues
88
{
9-
public static readonly MediaTypeHeaderValue ApplicationJson
10-
= MediaTypeHeaderValue.Parse("application/json").CopyAsReadOnly();
9+
public static readonly MediaTypeHeaderValue ApplicationJson = MediaTypeHeaderValue.Parse("application/json").CopyAsReadOnly();
1110

12-
public static readonly MediaTypeHeaderValue TextJson
13-
= MediaTypeHeaderValue.Parse("text/json").CopyAsReadOnly();
11+
public static readonly MediaTypeHeaderValue TextJson = MediaTypeHeaderValue.Parse("text/json").CopyAsReadOnly();
1412
}
1513
}

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/Internal/MvcPartialJsonLoggerExtensions.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ namespace PartialResponse.AspNetCore.Mvc.Formatters.Json.Internal
77
{
88
internal static class MvcPartialJsonLoggerExtensions
99
{
10-
private static readonly Action<ILogger, string, Exception> _partialJsonResultExecuting;
10+
private static readonly Action<ILogger, string, Exception> LogMessage;
1111

1212
static MvcPartialJsonLoggerExtensions()
1313
{
14-
_partialJsonResultExecuting = LoggerMessage.Define<string>(
15-
LogLevel.Information,
16-
1,
17-
"Executing PartialJsonResult, writing value {Value}.");
14+
LogMessage = LoggerMessage.Define<string>(LogLevel.Information, 1, "Executing PartialJsonResult, writing value {Value}.");
1815
}
1916

2017
public static void PartialJsonResultExecuting(this ILogger logger, object value)
2118
{
22-
_partialJsonResultExecuting(logger, Convert.ToString(value), null);
19+
LogMessage(logger, Convert.ToString(value), null);
2320
}
2421
}
2522
}

src/PartialResponse.AspNetCore.Mvc.Formatters.Json/Internal/MvcPartialJsonMvcOptionsSetup.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ namespace PartialResponse.AspNetCore.Mvc.Formatters.Json.Internal
1717
/// </summary>
1818
public class MvcPartialJsonMvcOptionsSetup : IConfigureOptions<MvcOptions>
1919
{
20-
private readonly ILoggerFactory _loggerFactory;
21-
private readonly MvcPartialJsonOptions _partialJsonOptions;
22-
private readonly ArrayPool<char> _charPool;
23-
private readonly ObjectPoolProvider _objectPoolProvider;
20+
private readonly ILoggerFactory loggerFactory;
21+
private readonly MvcPartialJsonOptions partialJsonOptions;
22+
private readonly ArrayPool<char> charPool;
23+
private readonly ObjectPoolProvider objectPoolProvider;
2424

25-
public MvcPartialJsonMvcOptionsSetup(
26-
ILoggerFactory loggerFactory,
27-
IOptions<MvcPartialJsonOptions> partialJsonOptions,
28-
ArrayPool<char> charPool,
29-
ObjectPoolProvider objectPoolProvider)
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="MvcPartialJsonMvcOptionsSetup"/> class.
27+
/// </summary>
28+
/// <param name="loggerFactory">The logger factory.</param>
29+
/// <param name="partialJsonOptions">The options.</param>
30+
/// <param name="charPool">The character array pool.</param>
31+
/// <param name="objectPoolProvider">The object pool provider.</param>
32+
public MvcPartialJsonMvcOptionsSetup(ILoggerFactory loggerFactory, IOptions<MvcPartialJsonOptions> partialJsonOptions, ArrayPool<char> charPool, ObjectPoolProvider objectPoolProvider)
3033
{
3134
if (loggerFactory == null)
3235
{
@@ -48,20 +51,20 @@ public MvcPartialJsonMvcOptionsSetup(
4851
throw new ArgumentNullException(nameof(objectPoolProvider));
4952
}
5053

51-
_loggerFactory = loggerFactory;
52-
_partialJsonOptions = partialJsonOptions.Value;
53-
_charPool = charPool;
54-
_objectPoolProvider = objectPoolProvider;
54+
this.loggerFactory = loggerFactory;
55+
this.partialJsonOptions = partialJsonOptions.Value;
56+
this.charPool = charPool;
57+
this.objectPoolProvider = objectPoolProvider;
5558
}
5659

60+
/// <summary>
61+
/// Configures the <see cref="MvcOptions"/> by adding the <see cref="PartialJsonOutputFormatter"/>.
62+
/// </summary>
63+
/// <param name="options">The MVC options.</param>
5764
public void Configure(MvcOptions options)
5865
{
59-
options.OutputFormatters.Add(new PartialJsonOutputFormatter(_partialJsonOptions.SerializerSettings, _charPool, _partialJsonOptions.IgnoreCase));
60-
61-
// TODO: Remove?
66+
options.OutputFormatters.Add(new PartialJsonOutputFormatter(this.partialJsonOptions.SerializerSettings, this.charPool, this.partialJsonOptions.IgnoreCase));
6267
options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValue.Parse("application/json"));
63-
64-
// TODO: Remove?
6568
options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(JToken)));
6669
}
6770
}

0 commit comments

Comments
 (0)