Skip to content

Commit f8874b8

Browse files
ilCosmicomartijn00
authored andcommitted
Fix compilation errors for .NET
- Replaced string-based IndexOf with char-based IndexOf for single character search. - Used static readonly field for split separators to comply with CA1861 recommendation. - Improved performance by avoiding unnecessary instantiation of arrays. No functional changes, only compilation fixes and minor optimizations.
1 parent 8bd0bce commit f8874b8

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

DSTV.Net/Data/Contour.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ private Contour(List<DstvContourPoint> pointList, ContourType type)
2323
[SuppressMessage("Design", "MA0016:Prefer returning collection abstraction instead of implementation", Justification = "This is a record")]
2424
public static IEnumerable<Contour> CreateSeveralContours(List<DstvContourPoint> pointList, ContourType type)
2525
{
26+
#if NET
27+
ArgumentNullException.ThrowIfNull(pointList, nameof(pointList));
28+
#else
2629
if (pointList is null) throw new ArgumentNullException(nameof(pointList));
30+
#endif
2731

2832
List<Contour> outList = new();
2933
if (type is ContourType.AK or ContourType.IK)

DSTV.Net/Data/DstvElement.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ public record DstvElement
99
{
1010
protected static string[] GetDataVector(string dstvElementLine, ISplitter splitter)
1111
{
12+
#if NET
13+
ArgumentNullException.ThrowIfNull(splitter, nameof(splitter));
14+
#else
1215
if (splitter is null) throw new ArgumentNullException(nameof(splitter));
16+
#endif
1317
if (Regex.IsMatch(dstvElementLine, "^\\*\\*.*", RegexOptions.None, TimeSpan.FromSeconds(1)))
1418
throw new DstvParseException("Attempt to get data from quote-line detected");
1519

@@ -24,7 +28,11 @@ protected static string[] GetDataVector(string dstvElementLine, ISplitter splitt
2428

2529
protected static string[] CorrectSplits(string[] separated, bool skipFirst = false, bool skipLast = false)
2630
{
31+
#if NET
32+
ArgumentNullException.ThrowIfNull(separated, nameof(separated));
33+
#else
2734
if (separated is null) throw new ArgumentNullException(nameof(separated));
35+
#endif
2836
for (var i = skipFirst ? 1 : 0; i < separated.Length - (skipLast ? 1 : 0); i++)
2937
{
3038
foreach (Match match in Regex.Matches(separated[i], "([^.\\d-]+)", RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(1)))

DSTV.Net/Implementations/DotSplitter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public string[] Split(string input)
1616
{
1717
var prevPos = 0;
1818
if (i > 0) prevPos = dotPoss[i - 1];
19-
dotPoss[i] = input.IndexOf(".", prevPos + 1, StringComparison.Ordinal);
19+
dotPoss[i] = input.IndexOf('.', prevPos + 1);
2020
}
2121

2222
var outArr = new string[n];

DSTV.Net/Implementations/DstvReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ public async Task<IDstv> ParseAsync(string dstvData)
1515

1616
public async Task<IDstv> ParseAsync(TextReader reader)
1717
{
18+
#if NET
19+
ArgumentNullException.ThrowIfNull(reader, nameof(reader));
20+
#else
1821
if (reader == null) throw new ArgumentNullException(nameof(reader));
22+
#endif
1923

2024
var context = new ReaderContext(reader);
2125

DSTV.Net/Implementations/FineSplitter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ internal class FineSplitter : ISplitter
99
/// <summary>
1010
/// Splitter for full carefully splitting - saving all lexemes
1111
/// </summary>
12-
public string[] Split(string input) => input.Split(new [] {" "}, StringSplitOptions.RemoveEmptyEntries);
12+
public string[] Split(string input) => input.Split(SplitSeparators, StringSplitOptions.RemoveEmptyEntries);
13+
14+
private static readonly char[] SplitSeparators = new char[] { ' ' };
15+
1316
}

0 commit comments

Comments
 (0)