Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanSaeed committed Aug 2, 2022
1 parent 48bfac1 commit 371f759
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 1 addition & 3 deletions Source/Serilog.Exceptions/Core/ExceptionEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var exceptionType = exception.GetType();

if (this.destructurers.ContainsKey(exceptionType))
if (this.destructurers.TryGetValue(exceptionType, out var destructurer))
{
var data = new ExceptionPropertiesBag(exception, this.destructuringOptions.Filter);

var destructurer = this.destructurers[exceptionType];
destructurer.Destructure(exception, data, this.DestructureException);

return data.GetResultDictionary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public void Destructure(
private static string? GetOrGenerateRefId(ref int nextCyclicRefId, IDictionary<string, object?> destructuredObject)
{
string? refId;
if (destructuredObject.ContainsKey(IdLabel))
if (destructuredObject.TryGetValue(IdLabel, out var value))
{
refId = (string?)destructuredObject[IdLabel];
refId = (string?)value;
}
else
{
Expand Down Expand Up @@ -269,9 +269,8 @@ private object DestructureValueDictionary(
IDictionary<object, IDictionary<string, object?>> destructuredObjects,
ref int nextCyclicRefId)
{
if (destructuredObjects.ContainsKey(value))
if (destructuredObjects.TryGetValue(value, out var destructuredObject))
{
var destructuredObject = destructuredObjects[value];
var refId = GetOrGenerateRefId(ref nextCyclicRefId, destructuredObject);

return new Dictionary<string, object?>
Expand Down Expand Up @@ -299,9 +298,8 @@ private object DestructureValueDictionary(
IDictionary<object, IDictionary<string, object?>> destructuredObjects,
ref int nextCyclicRefId)
{
if (destructuredObjects.ContainsKey(value))
if (destructuredObjects.TryGetValue(value, out var destructuredObject))
{
var destructuredObject = destructuredObjects[value];
var refId = GetOrGenerateRefId(ref nextCyclicRefId, destructuredObject);

return new Dictionary<string, object?>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ private static void MarkRedefinedPropertiesWithFullName(ReflectionPropertyInfo[]
var groupedByName = new Dictionary<string, List<ReflectionPropertyInfo>>();
foreach (var propertyInfo in propertyInfos)
{
if (groupedByName.ContainsKey(propertyInfo.Name))
if (groupedByName.TryGetValue(propertyInfo.Name, out var value))
{
groupedByName[propertyInfo.Name].Add(propertyInfo);
value.Add(propertyInfo);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public void DestructureComplexException_EachTypeOfPropertyIsDestructuredAsExpect
Assert.DoesNotContain(properties, x => string.Equals(x.Key, "PrivateProperty", StringComparison.Ordinal));
Assert.Equal("MessageValue", properties[nameof(TestException.Message)]);
#if NET461 || NET472
Assert.StartsWith("Void DestructureComplexException_EachTypeOfPropertyIsDestructuredAsExpected(", properties[nameof(TestException.TargetSite)].ToString());
Assert.StartsWith("Void DestructureComplexException_EachTypeOfPropertyIsDestructuredAsExpected(", properties[nameof(TestException.TargetSite)].ToString());
#endif
Assert.NotEmpty(properties[nameof(TestException.StackTrace)]?.ToString());
Assert.NotNull(properties[nameof(TestException.StackTrace)]?.ToString());
Assert.NotEmpty(properties[nameof(TestException.StackTrace)]?.ToString()!);
Assert.Equal("Serilog.Exceptions.Test", properties[nameof(TestException.Source)]);
Assert.Equal(-2146233088, properties[nameof(TestException.HResult)]);
Assert.Contains(typeof(TestException).FullName, properties["Type"]?.ToString(), StringComparison.Ordinal);
Assert.Contains(typeof(TestException).FullName!, properties["Type"]?.ToString(), StringComparison.Ordinal);
}

[Fact]
Expand Down

0 comments on commit 371f759

Please sign in to comment.