Skip to content

Commit

Permalink
Sealed private classes to fix Sonar smells (#5189)
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored Apr 9, 2023
1 parent b171b45 commit 9e92ca0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/NLog/Config/LoggingConfigurationParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ private static string GetName(Target target)
/// <summary>
/// Config element that's validated and having extra context
/// </summary>
private class ValidatedConfigurationElement : ILoggingConfigurationElement
private sealed class ValidatedConfigurationElement : ILoggingConfigurationElement
{
private static readonly IDictionary<string, string> EmptyDefaultDictionary = new SortHelpers.ReadOnlySingleBucketDictionary<string, string>();

Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Filters/WhenRepeatedFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private FilterResult RefreshFilterInfo(LogEventInfo logEvent, FilterInfo filterI
/// <summary>
/// Filter Value State (mutable)
/// </summary>
private class FilterInfo
private sealed class FilterInfo
{
public FilterInfo(StringBuilder stringBuilder)
{
Expand Down
10 changes: 5 additions & 5 deletions src/NLog/Internal/Collections/PropertiesDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public void Reset()
}
}

private class ParameterEnumerator : DictionaryEnumeratorBase, IEnumerator<MessageTemplateParameter>
private sealed class ParameterEnumerator : DictionaryEnumeratorBase, IEnumerator<MessageTemplateParameter>
{
/// <inheritDoc/>
public MessageTemplateParameter Current => CurrentParameter;
Expand All @@ -619,7 +619,7 @@ public ParameterEnumerator(PropertiesDictionary dictionary)
}
}

private class DictionaryEnumerator : DictionaryEnumeratorBase, IEnumerator<KeyValuePair<object, object>>
private sealed class DictionaryEnumerator : DictionaryEnumeratorBase, IEnumerator<KeyValuePair<object, object>>
{
/// <inheritDoc/>
public KeyValuePair<object, object> Current => CurrentProperty;
Expand All @@ -634,7 +634,7 @@ public DictionaryEnumerator(PropertiesDictionary dictionary)
}

[DebuggerDisplay("Count = {Count}")]
private class DictionaryCollection : ICollection<object>
private sealed class DictionaryCollection : ICollection<object>
{
private readonly PropertiesDictionary _dictionary;
private readonly bool _keyCollection;
Expand Down Expand Up @@ -708,7 +708,7 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}

private class DictionaryCollectionEnumerator : DictionaryEnumeratorBase, IEnumerator<object>
private sealed class DictionaryCollectionEnumerator : DictionaryEnumeratorBase, IEnumerator<object>
{
private readonly bool _keyCollection;

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

Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Layouts/CSV/CsvLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private bool ColumnValueRequiresQuotes(CsvQuotingMode quoting, StringBuilder sb,
/// </summary>
[ThreadAgnostic]
[AppDomainFixedOutput]
private class CsvHeaderLayout : Layout
private sealed class CsvHeaderLayout : Layout
{
private readonly CsvLayout _parent;
private string _headerOutput;
Expand Down
4 changes: 2 additions & 2 deletions src/NLog/SetupSerializationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static ISetupSerializationBuilder RegisterObjectTransformation(this ISetu
return setupBuilder;
}

private class ObjectTypeTransformation<T> : IObjectTypeTransformer
private sealed class ObjectTypeTransformation<T> : IObjectTypeTransformer
{
private readonly IObjectTypeTransformer _original;
private readonly Func<T, object> _transformer;
Expand All @@ -111,7 +111,7 @@ public object TryTransformObject(object obj)
}
}

private class ObjectTypeTransformation : IObjectTypeTransformer
private sealed class ObjectTypeTransformation : IObjectTypeTransformer
{
private readonly IObjectTypeTransformer _original;
private readonly Func<object, object> _transformer;
Expand Down
19 changes: 8 additions & 11 deletions tests/PackageLoaderTestAssembly/NLogPackageLoaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using NLog;
using NLog.Config;

namespace LoaderTestPublic
{
public class NLogPackageLoader
public sealed class NLogPackageLoader
{
public static void Preload()
{

// Nothing to do
}
}
}
Expand All @@ -53,7 +52,7 @@ namespace LoaderTestInternal
/// <summary>
/// private
/// </summary>
internal class NLogPackageLoader
internal sealed class NLogPackageLoader
{
public static void Preload()
{
Expand All @@ -66,8 +65,7 @@ namespace LoaderTestPrivateNested
{
internal class SomeType
{
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private class NLogPackageLoader
private sealed class NLogPackageLoader
{
public static void Preload(ConfigurationItemFactory fact)
{
Expand All @@ -82,9 +80,8 @@ public static void Preload(ConfigurationItemFactory fact)

namespace LoaderTestPrivateNestedStatic
{
internal class SomeType
internal sealed class SomeType
{
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private static class NLogPackageLoader
{
public static void Preload()
Expand All @@ -97,7 +94,7 @@ public static void Preload()

namespace LoaderTestWrong1
{
public class NLogPackageLoader
public sealed class NLogPackageLoader
{
[DebuggerStepThrough]
public static void Preload()
Expand All @@ -109,7 +106,7 @@ public static void Preload()

namespace LoaderTestWrong2
{
public class NLogPackageLoader
public sealed class NLogPackageLoader
{
public void Preload()
{
Expand All @@ -120,7 +117,7 @@ public void Preload()

namespace LoaderTestWrong3
{
public class NLogPackageLoader
public sealed class NLogPackageLoader
{
public static void Preload(int arg1, int arg2)
{
Expand Down

0 comments on commit 9e92ca0

Please sign in to comment.