Skip to content

Commit f69bf83

Browse files
authored
Code Enhancements (#794)
* Let private members readonly * Use long.TryParse * Sealed internal types * Sealed private types
1 parent 01b2aa8 commit f69bf83

9 files changed

+16
-19
lines changed

src/KubernetesClient/Autorest/StringTokenProvider.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace k8s.Autorest
1212
/// </summary>
1313
public sealed class StringTokenProvider : ITokenProvider
1414
{
15-
private string _accessToken;
16-
private string _type;
15+
private readonly string _accessToken;
16+
private readonly string _type;
1717

1818
/// <summary>
1919
/// Initializes a new instance of the <see cref="StringTokenProvider"/> class.
@@ -31,10 +31,7 @@ public StringTokenProvider(string accessToken, string tokenType)
3131
/// <summary>
3232
/// Gets the token type of this access token.
3333
/// </summary>
34-
public string TokenType
35-
{
36-
get { return _type; }
37-
}
34+
public string TokenType => _type;
3835

3936
/// <summary>
4037
/// Returns the static access token.

src/KubernetesClient/IntOrStringConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace k8s.Models
22
{
3-
internal class IntOrStringConverter : JsonConverter<IntstrIntOrString>
3+
internal sealed class IntOrStringConverter : JsonConverter<IntstrIntOrString>
44
{
55
public override IntstrIntOrString Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
66
{
@@ -21,7 +21,7 @@ public override void Write(Utf8JsonWriter writer, IntstrIntOrString value, JsonS
2121
{
2222
var s = value?.Value;
2323

24-
if (int.TryParse(s, out var intv))
24+
if (long.TryParse(s, out var intv))
2525
{
2626
writer.WriteNumberValue(intv);
2727
return;

src/KubernetesClient/Kubernetes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private async Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMes
102102
return result;
103103
}
104104

105-
private class QueryBuilder
105+
private sealed class QueryBuilder
106106
{
107107
private List<string> parameters = new List<string>();
108108

src/KubernetesClient/KubernetesJson.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal static class KubernetesJson
99
{
1010
private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions();
1111

12-
private class Iso8601TimeSpanConverter : JsonConverter<TimeSpan>
12+
private sealed class Iso8601TimeSpanConverter : JsonConverter<TimeSpan>
1313
{
1414
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
1515
{
@@ -24,7 +24,7 @@ public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializer
2424
}
2525
}
2626

27-
private class KubernetesDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
27+
private sealed class KubernetesDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
2828
{
2929
private const string SerializeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.ffffffK";
3030
private const string Iso8601Format = "yyyy'-'MM'-'dd'T'HH':'mm':'ssK";
@@ -41,7 +41,7 @@ public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSeri
4141
}
4242
}
4343

44-
private class KubernetesDateTimeConverter : JsonConverter<DateTime>
44+
private sealed class KubernetesDateTimeConverter : JsonConverter<DateTime>
4545
{
4646
private static readonly JsonConverter<DateTimeOffset> UtcConverter = new KubernetesDateTimeOffsetConverter();
4747
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)

src/KubernetesClient/LineSeparatedHttpContent.cs

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

77
namespace k8s
88
{
9-
internal class LineSeparatedHttpContent : HttpContent
9+
internal sealed class LineSeparatedHttpContent : HttpContent
1010
{
1111
private readonly HttpContent _originContent;
1212
private readonly CancellationToken _cancellationToken;
@@ -41,7 +41,7 @@ protected override bool TryComputeLength(out long length)
4141
return false;
4242
}
4343

44-
internal class CancelableStream : Stream
44+
internal sealed class CancelableStream : Stream
4545
{
4646
private readonly Stream _innerStream;
4747
private readonly CancellationToken _cancellationToken;
@@ -149,7 +149,7 @@ public void Dispose()
149149
}
150150
}
151151

152-
internal class PeekableStreamReader : TextReader
152+
internal sealed class PeekableStreamReader : TextReader
153153
{
154154
private readonly Queue<string> _buffer;
155155
private readonly StreamReader _inner;

src/KubernetesClient/QuantityConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace k8s.Models
22
{
3-
internal class QuantityConverter : JsonConverter<ResourceQuantity>
3+
internal sealed class QuantityConverter : JsonConverter<ResourceQuantity>
44
{
55
public override ResourceQuantity Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
66
{

src/KubernetesClient/ResourceQuantity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static implicit operator ResourceQuantity(decimal v)
233233
return new ResourceQuantity(v, 0, SuffixFormat.DecimalExponent);
234234
}
235235

236-
private class Suffixer
236+
private sealed class Suffixer
237237
{
238238
private static readonly IReadOnlyDictionary<string, (int, int)> BinSuffixes =
239239
new Dictionary<string, (int, int)>

src/KubernetesClient/V1PatchJsonConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace k8s.Models
22
{
3-
internal class V1PatchJsonConverter : JsonConverter<V1Patch>
3+
internal sealed class V1PatchJsonConverter : JsonConverter<V1Patch>
44
{
55
public override V1Patch Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
66
{

src/KubernetesClient/V1Status.ObjectView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace k8s.Models
22
{
33
public partial class V1Status
44
{
5-
internal class V1StatusObjectViewConverter : JsonConverter<V1Status>
5+
internal sealed class V1StatusObjectViewConverter : JsonConverter<V1Status>
66
{
77
public override V1Status Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
88
{

0 commit comments

Comments
 (0)