Skip to content

Commit 99058cf

Browse files
authored
dotnet: small code cleanup / no change of functionality and/or interface (#399)
* code cleanup / no change of functionality and/or interface * code cleanup in tests * cleanup warnings
1 parent bbb04de commit 99058cf

File tree

7 files changed

+512
-538
lines changed

7 files changed

+512
-538
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=15b5b1f1_002D457c_002D4ca6_002Db278_002D5615aedc07d3/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="_" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
3+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=236f7aa5_002D7b06_002D43ca_002Dbf2a_002D9b31bfcff09a/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Private" Description="Constant fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="CONSTANT_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AA_BB" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String></wpf:ResourceDictionary>
Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
8-
namespace Cucumber.HtmlFormatter;
1+
namespace Cucumber.HtmlFormatter;
92

103
public class JsonInHtmlWriter : StreamWriter
114
{
12-
private readonly int BUFFER_SIZE = 1024;
13-
private StreamWriter Writer;
14-
private char[] escapeBuffer;
5+
private const int BUFFER_SIZE = 1024;
6+
private readonly StreamWriter _writer;
7+
private readonly char[] _escapeBuffer;
158

169
public JsonInHtmlWriter(StreamWriter writer) : base(writer.BaseStream)
1710
{
18-
Writer = writer;
19-
escapeBuffer = new char[BUFFER_SIZE]; // Initialize escapeBuffer
11+
_writer = writer;
12+
_escapeBuffer = new char[BUFFER_SIZE]; // Initialize escapeBuffer
2013
}
2114

2215
public override void Write(string value)
@@ -39,17 +32,17 @@ public override void Write(char[] source, int offset, int length)
3932
if (offset + length > source.GetLength(0))
4033
throw new ArgumentException("Cannot read past the end of the input source char array.");
4134

42-
char[] destination = PrepareBuffer();
43-
int flushAt = BUFFER_SIZE - 2;
44-
int written = 0;
45-
for (int i = offset; i < offset + length; i++)
35+
var destination = PrepareBuffer();
36+
var flushAt = BUFFER_SIZE - 2;
37+
var written = 0;
38+
for (var i = offset; i < offset + length; i++)
4639
{
47-
char c = source[i];
40+
var c = source[i];
4841

4942
// Flush buffer if (nearly) full
5043
if (written >= flushAt)
5144
{
52-
Writer.Write(destination, 0, written);
45+
_writer.Write(destination, 0, written);
5346
written = 0;
5447
}
5548

@@ -63,7 +56,7 @@ public override void Write(char[] source, int offset, int length)
6356
// Flush any remaining
6457
if (written > 0)
6558
{
66-
Writer.Write(destination, 0, written);
59+
_writer.Write(destination, 0, written);
6760
}
6861
}
6962

@@ -72,17 +65,17 @@ public override async Task WriteAsync(char[] source, int offset, int length)
7265
if (offset + length > source.GetLength(0))
7366
throw new ArgumentException("Cannot read past the end of the input source char array.");
7467

75-
char[] destination = PrepareBuffer();
76-
int flushAt = BUFFER_SIZE - 2;
77-
int written = 0;
78-
for (int i = offset; i < offset + length; i++)
68+
var destination = PrepareBuffer();
69+
var flushAt = BUFFER_SIZE - 2;
70+
var written = 0;
71+
for (var i = offset; i < offset + length; i++)
7972
{
8073
char c = source[i];
8174

8275
// Flush buffer if (nearly) full
8376
if (written >= flushAt)
8477
{
85-
await Writer.WriteAsync(destination, 0, written);
78+
await _writer.WriteAsync(destination, 0, written);
8679
written = 0;
8780
}
8881

@@ -96,28 +89,28 @@ public override async Task WriteAsync(char[] source, int offset, int length)
9689
// Flush any remaining
9790
if (written > 0)
9891
{
99-
await Writer.WriteAsync(destination, 0, written);
92+
await _writer.WriteAsync(destination, 0, written);
10093
}
10194
}
95+
10296
private char[] PrepareBuffer()
10397
{
10498
// Reuse the same buffer, avoids repeated array allocation
105-
escapeBuffer ??= new char[BUFFER_SIZE];
106-
return escapeBuffer;
99+
return _escapeBuffer;
107100
}
108101

109102
public override void Flush()
110103
{
111-
Writer.Flush();
104+
_writer.Flush();
112105
}
113106

114107
public override async Task FlushAsync()
115108
{
116-
await Writer.FlushAsync();
109+
await _writer.FlushAsync();
117110
}
118111

119112
public override void Close()
120113
{
121-
Writer.Close();
114+
_writer.Close();
122115
}
123116
}

0 commit comments

Comments
 (0)