Skip to content

Commit

Permalink
Suppress some warnings, tidy up some namespacing (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Mar 30, 2023
1 parent 29d842d commit 8bb02df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Serilog;
namespace Serilog.Rendering;

/// <summary>
/// Class that provides reusable StringWriters to reduce memory allocations
/// </summary>
internal class ReusableStringWriter : StringWriter
class ReusableStringWriter : StringWriter
{
[ThreadStatic]
static ReusableStringWriter? _pooledWriter;
Expand Down
6 changes: 1 addition & 5 deletions src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif

namespace Serilog.Settings.KeyValuePairs;

#if !NET5_0
Expand Down Expand Up @@ -250,7 +246,7 @@ static void ApplyDirectives(List<IGrouping<string, ConfigurationMethodCall>> dir
select SuppressConvertCall(directive, p)).ToList();

// Work around inability to annotate lambdas in query expressions. The parent *must* have RUC for safety.
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026")]
[UnconditionalSuppressMessage("Trimming", "IL2026")]
object? SuppressConvertCall(ConfigurationMethodCall? directive, ParameterInfo p)
=> directive == null ? p.DefaultValue : ConvertOrLookupByName(directive.Value, p.ParameterType, declaredSwitches);

Expand Down
17 changes: 6 additions & 11 deletions test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable UnusedAutoPropertyAccessor.Global, UnusedParameter.Local
// ReSharper disable UnusedAutoPropertyAccessor.Global, UnusedParameter.Local, ParameterOnlyUsedForPreconditionCheck.Local, RedundantExplicitNullableCreation, MemberHidesStaticFromOuterClass
// ReSharper disable UnusedAutoPropertyAccessor.Local, UnusedMemberInSuper.Global, UnusedMember.Local, UseObjectOrCollectionInitializer, UnusedAutoPropertyAccessor.Local

namespace Serilog.Tests.Capturing;

Expand Down Expand Up @@ -53,7 +54,7 @@ void DoThreadTest(object logObject, Action<string?> assertAction)

Assert.IsType<StructureValue>(propValue);

var result = ((StructureValue)propValue).Properties.SingleOrDefault(p => p.Name == "Root")?.Value?.ToString();
var result = ((StructureValue)propValue).Properties.SingleOrDefault(p => p.Name == "Root")?.Value.ToString();

assertAction.Invoke(result);
}
Expand All @@ -63,7 +64,7 @@ void DoThreadTest(object logObject, Action<string?> assertAction)
[Fact]
public void UnderDestructuringAByteArrayIsAScalarValue()
{
var pv = _converter.CreatePropertyValue(new byte[0], Destructuring.Destructure);
var pv = _converter.CreatePropertyValue(Array.Empty<byte>(), Destructuring.Destructure);
Assert.IsType<ScalarValue>(pv);
Assert.IsType<string>(((ScalarValue)pv).Value);
}
Expand All @@ -79,7 +80,7 @@ public void UnderDestructuringABooleanIsAScalarValue()
[Fact]
public void UnderDestructuringAnIntegerArrayIsASequenceValue()
{
var pv = _converter.CreatePropertyValue(new int[0], Destructuring.Destructure);
var pv = _converter.CreatePropertyValue(Array.Empty<int>(), Destructuring.Destructure);
Assert.IsType<SequenceValue>(pv);
}

Expand All @@ -93,9 +94,7 @@ public void ByDefaultADestructuredNullNullableIsAScalarNull()
[Fact]
public void ByDefaultADestructuredNonNullNullableIsItsValue()
{
// ReSharper disable RedundantExplicitNullableCreation
var pv = _converter.CreatePropertyValue(new int?(2), Destructuring.Destructure);
// ReSharper restore RedundantExplicitNullableCreation
Assert.Equal(2, ((ScalarValue)pv).Value);
}

Expand All @@ -106,9 +105,7 @@ class A

class B
{
// ReSharper disable UnusedAutoPropertyAccessor.Local
public A? A { get; set; }
// ReSharper restore UnusedAutoPropertyAccessor.Local
}

[Fact]
Expand All @@ -128,8 +125,6 @@ struct C

class D
{
// ReSharper disable once MemberHidesStaticFromOuterClass
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public IList<C?>? C { get; set; }
}

Expand Down Expand Up @@ -225,7 +220,7 @@ public void ByteSpansAreConvertedToTheSameStringsAsArrays(int length)
[Fact]
public void FailsGracefullyWhenAccessingPropertiesViaReflectionThrows()
{
var thrower = new int[] { 1, 2, 3 }.AsMemory();
var thrower = new[] { 1, 2, 3 }.AsMemory();

var pv = _converter.CreatePropertyValue(thrower, Destructuring.Destructure);
var sv = (StructureValue)pv;
Expand Down

0 comments on commit 8bb02df

Please sign in to comment.