From 6e124141017d139b71519298a6d424fbab682b07 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Wed, 24 Jan 2024 20:28:21 +0300 Subject: [PATCH] CodeQL warnings (#97) --- .../AttributedDestructuringPolicy.cs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Destructurama.Attributed/Attributed/AttributedDestructuringPolicy.cs b/src/Destructurama.Attributed/Attributed/AttributedDestructuringPolicy.cs index cd5beb3..f0b9c28 100644 --- a/src/Destructurama.Attributed/Attributed/AttributedDestructuringPolicy.cs +++ b/src/Destructurama.Attributed/Attributed/AttributedDestructuringPolicy.cs @@ -71,11 +71,8 @@ private CacheEntry CreateCacheEntry(Type type) .Where(o => o.Attribute != null) .ToDictionary(o => o.pi, o => o.Attribute); - if (_options.IgnoreNullProperties && !optionalIgnoreAttributes.Any() && !destructuringAttributes.Any()) - { - if (typeof(IEnumerable).IsAssignableFrom(type)) - return CacheEntry.Ignore; - } + if (_options.IgnoreNullProperties && !optionalIgnoreAttributes.Any() && !destructuringAttributes.Any() && typeof(IEnumerable).IsAssignableFrom(type)) + return CacheEntry.Ignore; return new CacheEntry((o, f) => MakeStructure(o, properties, optionalIgnoreAttributes, destructuringAttributes, f, type)); } @@ -93,17 +90,11 @@ private LogEventPropertyValue MakeStructure( { var propValue = SafeGetPropValue(o, pi); - if (optionalIgnoreAttributes.TryGetValue(pi, out var optionalIgnoreAttribute)) - { - if (optionalIgnoreAttribute.ShouldPropertyBeIgnored(pi.Name, propValue, pi.PropertyType)) - continue; - } + if (optionalIgnoreAttributes.TryGetValue(pi, out var optionalIgnoreAttribute) && optionalIgnoreAttribute.ShouldPropertyBeIgnored(pi.Name, propValue, pi.PropertyType)) + continue; - if (_options.IgnoreNullProperties) - { - if (NotLoggedIfNullAttribute.Instance.ShouldPropertyBeIgnored(pi.Name, propValue, pi.PropertyType)) - continue; - } + if (_options.IgnoreNullProperties && NotLoggedIfNullAttribute.Instance.ShouldPropertyBeIgnored(pi.Name, propValue, pi.PropertyType)) + continue; if (destructuringAttributes.TryGetValue(pi, out var destructuringAttribute)) {