Skip to content

Commit 354d24c

Browse files
Randall FlaggRandall Flagg
authored andcommitted
Fixed a few more warnings
1 parent 4c4e2a8 commit 354d24c

File tree

9 files changed

+50
-30
lines changed

9 files changed

+50
-30
lines changed

src/.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ dotnet_style_allow_statement_immediately_after_block_experimental = false:warnin
8989
#### C# Coding Conventions ####
9090

9191
# var preferences
92-
csharp_style_var_elsewhere = false:suggestion
92+
csharp_style_var_elsewhere = true:suggestion
9393
csharp_style_var_for_built_in_types = true:warning
9494
csharp_style_var_when_type_is_apparent = true:warning
9595

@@ -277,7 +277,7 @@ dotnet_diagnostic.IDE0003.severity = warning
277277
dotnet_diagnostic.IDE0004.severity = warning
278278

279279
# IDE0005: Remove unnecessary import
280-
dotnet_diagnostic.IDE0005.severity = warning
280+
dotnet_diagnostic.IDE0005.severity = none
281281

282282
# IDE0005_gen: Remove unnecessary import (NotConfigurable)
283283
#dotnet_diagnostic.IDE0005_gen.severity = silent

src/ColumnizerLib/Column.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ public class Column : IColumn
1010
private const int MAXLENGTH = 4678 - 3;
1111
private const string REPLACEMENT = "...";
1212

13-
private static readonly IEnumerable<Func<string, string>> _replacements;
13+
private static readonly List<Func<string, string>> _replacements = [
14+
//replace tab with 3 spaces, from old coding. Needed???
15+
input => input.Replace("\t", " ", StringComparison.Ordinal),
16+
17+
//shorten string if it exceeds maxLength
18+
input => input.Length > MAXLENGTH
19+
? string.Concat(input.AsSpan(0, MAXLENGTH), REPLACEMENT)
20+
: input
21+
];
1422

1523
private string _fullValue;
1624

@@ -20,32 +28,19 @@ public class Column : IColumn
2028

2129
static Column ()
2230
{
23-
var replacements = new List<Func<string, string>>(
24-
[
25-
//replace tab with 3 spaces, from old coding. Needed???
26-
input => input.Replace("\t", " ", StringComparison.Ordinal),
27-
28-
//shorten string if it exceeds maxLength
29-
input => input.Length > MAXLENGTH
30-
? string.Concat(input.AsSpan(0, MAXLENGTH), REPLACEMENT)
31-
: input
32-
]);
33-
3431
if (Environment.Version >= Version.Parse("6.2"))
3532
{
3633
//Win8 or newer support full UTF8 chars with the preinstalled fonts.
3734
//Replace null char with UTF8 Symbol U+2400 (␀)
38-
replacements.Add(input => input.Replace("\0", "␀", StringComparison.Ordinal));
35+
_replacements.Add(input => input.Replace("\0", "␀", StringComparison.Ordinal));
3936
}
4037
else
4138
{
4239
//Everything below Win8 the installed fonts seems to not to support reliabel
4340
//Replace null char with space
44-
replacements.Add(input => input.Replace("\0", " ", StringComparison.Ordinal));
41+
_replacements.Add(input => input.Replace("\0", " ", StringComparison.Ordinal));
4542
}
4643

47-
_replacements = replacements;
48-
4944
EmptyColumn = new Column { FullValue = string.Empty };
5045
}
5146

@@ -77,7 +72,7 @@ public string FullValue
7772

7873
public string DisplayValue { get; private set; }
7974

80-
string ITextValue.Text => DisplayValue;
75+
public string Text => DisplayValue;
8176

8277
#endregion
8378

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
namespace LogExpert.Extensions;
22

3+
//TODO: Move this to LogExpert.UI, change to internal and fix tests
34
public static class LogLineExtensions
45
{
5-
public static string ToClipBoardText(this ILogLine logLine)
6+
//TOOD: check if the callers are checking for null before calling
7+
public static string ToClipBoardText (this ILogLine logLine)
68
{
7-
return "\t" + (logLine.LineNumber + 1).ToString() + "\t" + logLine.FullLine;
9+
return logLine == null ? string.Empty : $"\t{logLine.LineNumber + 1}\t{logLine.FullLine}";
810
}
911
}

src/ColumnizerLib/IXmlLogConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface IXmlLogConfiguration
3030
/// Example: {"log4j", "http://jakarta.apache.org/log4j"}
3131
///
3232
/// </summary>
33-
string[] Namespace { get; }
33+
string[] GetNamespaceDeclaration ();
3434

3535
#endregion
3636
}

src/ColumnizerLib/LineEntry.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
using System;
2+
13
namespace LogExpert;
24

35
/// <summary>
46
/// This helper struct holds a log line and its line number (zero based).
57
/// This struct is used by <see cref="ILogExpertCallback"/>.
68
/// </summary>
79
/// <seealso cref="ILogExpertCallback.AddPipedTab"/>
8-
public struct LineEntry
10+
public struct LineEntry : IEquatable<LineEntry>
911
{
1012
/// <summary>
1113
/// The content of the line.
@@ -16,4 +18,22 @@ public struct LineEntry
1618
/// The line number. See <see cref="ILogExpertCallback.AddPipedTab"/> for an explanation of the line number.
1719
/// </summary>
1820
public int LineNum { get; set; }
21+
22+
public override bool Equals(object obj)
23+
{
24+
return obj is LineEntry other && Equals(other);
25+
}
26+
27+
public readonly bool Equals(LineEntry other)
28+
{
29+
return LineNum == other.LineNum && Equals(LogLine, other.LogLine);
30+
}
31+
32+
public override readonly int GetHashCode()
33+
{
34+
return HashCode.Combine(LineNum, LogLine);
35+
}
36+
37+
public static bool operator == (LineEntry left, LineEntry right) => left.Equals(right);
38+
public static bool operator != (LineEntry left, LineEntry right) => !left.Equals(right);
1939
}

src/GlassfishColumnizer/XmlConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LogExpert;
1+
using LogExpert;
22

33
namespace GlassfishColumnizer;
44

@@ -12,7 +12,7 @@ internal class XmlConfig : IXmlLogConfiguration
1212

1313
public string Stylesheet { get; }
1414

15-
public string[] Namespace => null;
15+
public string[] GetNamespaceDeclaration () => null;
1616

1717
#endregion
1818
}

src/Log4jXmlColumnizer/XmlConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LogExpert;
1+
using LogExpert;
22

33
namespace Log4jXmlColumnizer;
44

@@ -26,7 +26,7 @@ internal class XmlConfig : IXmlLogConfiguration
2626
"</xsl:template>" +
2727
"</xsl:stylesheet>";
2828

29-
public string[] Namespace => ["log4j", "http://jakarta.apache.org/log4j"];
29+
public string[] GetNamespaceDeclaration () => ["log4j", "http://jakarta.apache.org/log4j"];
3030

3131
#endregion
3232
}

src/LogExpert.Core/Classes/DateTimeParser/Token.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ namespace LogExpert.Core.Classes.DateTimeParser;
44

55
public static class Token
66
{
7+
//TOOD: check if the callers are checking for null before calling
78
public static bool IsDatePart(string token)
89
{
10+
ArgumentNullException.ThrowIfNull(token);
911
return
1012
token.StartsWith("y", StringComparison.OrdinalIgnoreCase) ||
1113
token.StartsWith("m", StringComparison.OrdinalIgnoreCase) ||
1214
token.StartsWith("d", StringComparison.OrdinalIgnoreCase) ||
1315
token.StartsWith("s", StringComparison.OrdinalIgnoreCase) ||
1416
token.StartsWith("h", StringComparison.OrdinalIgnoreCase) ||
15-
string.Compare(token, "tt", StringComparison.OrdinalIgnoreCase) == 0;
17+
token.Equals("tt", StringComparison.OrdinalIgnoreCase);
1618
}
1719
}

src/LogExpert.Core/Classes/xml/XmlBlockSplitter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ public XmlBlockSplitter(XmlLogReader reader, IXmlLogConfiguration xmlLogConfig)
3939
// Create the XmlNamespaceManager.
4040
NameTable nt = new();
4141
XmlNamespaceManager nsmgr = new(nt);
42-
if (xmlLogConfig.Namespace != null)
42+
var namespaceDeclaration = xmlLogConfig.GetNamespaceDeclaration();
43+
if (namespaceDeclaration != null)
4344
{
44-
nsmgr.AddNamespace(xmlLogConfig.Namespace[0], xmlLogConfig.Namespace[1]);
45+
nsmgr.AddNamespace(namespaceDeclaration[0], namespaceDeclaration[1]);
4546
}
4647
// Create the XmlParserContext.
4748
_context = new XmlParserContext(nt, nsmgr, null, XmlSpace.None);

0 commit comments

Comments
 (0)