Skip to content

Commit 9e92ca0

Browse files
authored
Sealed private classes to fix Sonar smells (#5189)
1 parent b171b45 commit 9e92ca0

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

src/NLog/Config/LoggingConfigurationParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ private static string GetName(Target target)
14331433
/// <summary>
14341434
/// Config element that's validated and having extra context
14351435
/// </summary>
1436-
private class ValidatedConfigurationElement : ILoggingConfigurationElement
1436+
private sealed class ValidatedConfigurationElement : ILoggingConfigurationElement
14371437
{
14381438
private static readonly IDictionary<string, string> EmptyDefaultDictionary = new SortHelpers.ReadOnlySingleBucketDictionary<string, string>();
14391439

src/NLog/Filters/WhenRepeatedFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private FilterResult RefreshFilterInfo(LogEventInfo logEvent, FilterInfo filterI
301301
/// <summary>
302302
/// Filter Value State (mutable)
303303
/// </summary>
304-
private class FilterInfo
304+
private sealed class FilterInfo
305305
{
306306
public FilterInfo(StringBuilder stringBuilder)
307307
{

src/NLog/Internal/Collections/PropertiesDictionary.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public void Reset()
605605
}
606606
}
607607

608-
private class ParameterEnumerator : DictionaryEnumeratorBase, IEnumerator<MessageTemplateParameter>
608+
private sealed class ParameterEnumerator : DictionaryEnumeratorBase, IEnumerator<MessageTemplateParameter>
609609
{
610610
/// <inheritDoc/>
611611
public MessageTemplateParameter Current => CurrentParameter;
@@ -619,7 +619,7 @@ public ParameterEnumerator(PropertiesDictionary dictionary)
619619
}
620620
}
621621

622-
private class DictionaryEnumerator : DictionaryEnumeratorBase, IEnumerator<KeyValuePair<object, object>>
622+
private sealed class DictionaryEnumerator : DictionaryEnumeratorBase, IEnumerator<KeyValuePair<object, object>>
623623
{
624624
/// <inheritDoc/>
625625
public KeyValuePair<object, object> Current => CurrentProperty;
@@ -634,7 +634,7 @@ public DictionaryEnumerator(PropertiesDictionary dictionary)
634634
}
635635

636636
[DebuggerDisplay("Count = {Count}")]
637-
private class DictionaryCollection : ICollection<object>
637+
private sealed class DictionaryCollection : ICollection<object>
638638
{
639639
private readonly PropertiesDictionary _dictionary;
640640
private readonly bool _keyCollection;
@@ -708,7 +708,7 @@ IEnumerator IEnumerable.GetEnumerator()
708708
return GetEnumerator();
709709
}
710710

711-
private class DictionaryCollectionEnumerator : DictionaryEnumeratorBase, IEnumerator<object>
711+
private sealed class DictionaryCollectionEnumerator : DictionaryEnumeratorBase, IEnumerator<object>
712712
{
713713
private readonly bool _keyCollection;
714714

@@ -769,7 +769,7 @@ internal static bool Equals(string x, string y)
769769
/// Property-Key equality-comparer that uses string-hashcode from OrdinalIgnoreCase
770770
/// Enables case-insensitive lookup using <see cref="IgnoreCasePropertyKey"/>
771771
/// </summary>
772-
private class PropertyKeyComparer : IEqualityComparer<object>
772+
private sealed class PropertyKeyComparer : IEqualityComparer<object>
773773
{
774774
public static readonly PropertyKeyComparer Default = new PropertyKeyComparer();
775775

src/NLog/Layouts/CSV/CsvLayout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ private bool ColumnValueRequiresQuotes(CsvQuotingMode quoting, StringBuilder sb,
251251
/// </summary>
252252
[ThreadAgnostic]
253253
[AppDomainFixedOutput]
254-
private class CsvHeaderLayout : Layout
254+
private sealed class CsvHeaderLayout : Layout
255255
{
256256
private readonly CsvLayout _parent;
257257
private string _headerOutput;

src/NLog/SetupSerializationBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static ISetupSerializationBuilder RegisterObjectTransformation(this ISetu
8888
return setupBuilder;
8989
}
9090

91-
private class ObjectTypeTransformation<T> : IObjectTypeTransformer
91+
private sealed class ObjectTypeTransformation<T> : IObjectTypeTransformer
9292
{
9393
private readonly IObjectTypeTransformer _original;
9494
private readonly Func<T, object> _transformer;
@@ -111,7 +111,7 @@ public object TryTransformObject(object obj)
111111
}
112112
}
113113

114-
private class ObjectTypeTransformation : IObjectTypeTransformer
114+
private sealed class ObjectTypeTransformation : IObjectTypeTransformer
115115
{
116116
private readonly IObjectTypeTransformer _original;
117117
private readonly Func<object, object> _transformer;

tests/PackageLoaderTestAssembly/NLogPackageLoaders.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@
3333

3434
using System;
3535
using System.Diagnostics;
36-
using System.Diagnostics.CodeAnalysis;
3736
using NLog;
3837
using NLog.Config;
3938

4039
namespace LoaderTestPublic
4140
{
42-
public class NLogPackageLoader
41+
public sealed class NLogPackageLoader
4342
{
4443
public static void Preload()
4544
{
46-
45+
// Nothing to do
4746
}
4847
}
4948
}
@@ -53,7 +52,7 @@ namespace LoaderTestInternal
5352
/// <summary>
5453
/// private
5554
/// </summary>
56-
internal class NLogPackageLoader
55+
internal sealed class NLogPackageLoader
5756
{
5857
public static void Preload()
5958
{
@@ -66,8 +65,7 @@ namespace LoaderTestPrivateNested
6665
{
6766
internal class SomeType
6867
{
69-
[SuppressMessage("ReSharper", "UnusedMember.Local")]
70-
private class NLogPackageLoader
68+
private sealed class NLogPackageLoader
7169
{
7270
public static void Preload(ConfigurationItemFactory fact)
7371
{
@@ -82,9 +80,8 @@ public static void Preload(ConfigurationItemFactory fact)
8280

8381
namespace LoaderTestPrivateNestedStatic
8482
{
85-
internal class SomeType
83+
internal sealed class SomeType
8684
{
87-
[SuppressMessage("ReSharper", "UnusedMember.Local")]
8885
private static class NLogPackageLoader
8986
{
9087
public static void Preload()
@@ -97,7 +94,7 @@ public static void Preload()
9794

9895
namespace LoaderTestWrong1
9996
{
100-
public class NLogPackageLoader
97+
public sealed class NLogPackageLoader
10198
{
10299
[DebuggerStepThrough]
103100
public static void Preload()
@@ -109,7 +106,7 @@ public static void Preload()
109106

110107
namespace LoaderTestWrong2
111108
{
112-
public class NLogPackageLoader
109+
public sealed class NLogPackageLoader
113110
{
114111
public void Preload()
115112
{
@@ -120,7 +117,7 @@ public void Preload()
120117

121118
namespace LoaderTestWrong3
122119
{
123-
public class NLogPackageLoader
120+
public sealed class NLogPackageLoader
124121
{
125122
public static void Preload(int arg1, int arg2)
126123
{

0 commit comments

Comments
 (0)