From b4e84ae070ca7487756f6b8bbbd1091b0165d776 Mon Sep 17 00:00:00 2001 From: Roland Banks Date: Wed, 8 Jul 2026 15:21:27 +0700 Subject: [PATCH] Simplify IsNavigationProperty to reduce cyclomatic complexity Codacy flagged the sequential if-statement chain (complexity 15). Collapses the primitive/enum/well-known-scalar-type checks into a single condition backed by a HashSet lookup, and drops the now-redundant "!= typeof(string)" guard on the collection check (string is already excluded by the scalar-type set by that point). Pure internal simplification, no behavior change - full suite green (786/786), including all scalar/navigation classification tests. --- .../MemberPathResolver.cs | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/PanoramicData.OData.Client/MemberPathResolver.cs b/PanoramicData.OData.Client/MemberPathResolver.cs index 4ca7f0e..08e7dfb 100644 --- a/PanoramicData.OData.Client/MemberPathResolver.cs +++ b/PanoramicData.OData.Client/MemberPathResolver.cs @@ -119,6 +119,23 @@ internal static bool TryGetLeafMemberNameLoose(Expression expression, out string return false; } + /// + /// Well-known scalar (non-navigation) reference/value types that aren't caught by + /// or . + /// + private static readonly HashSet _scalarTypes = + [ + typeof(string), + typeof(DateTime), + typeof(DateTimeOffset), + typeof(DateOnly), + typeof(TimeOnly), + typeof(TimeSpan), + typeof(Guid), + typeof(decimal), + typeof(byte[]) + ]; + /// /// Determines if a property is a navigation property (vs a scalar property). /// Navigation properties are entity references or collections of entities. @@ -135,40 +152,14 @@ internal static bool IsNavigationProperty(PropertyInfo property) propertyType = underlyingType; } - // Primitives are scalar - if (propertyType.IsPrimitive) - { - return false; - } - - // Common scalar types - if (propertyType == typeof(string) || - propertyType == typeof(DateTime) || - propertyType == typeof(DateTimeOffset) || - propertyType == typeof(DateOnly) || - propertyType == typeof(TimeOnly) || - propertyType == typeof(TimeSpan) || - propertyType == typeof(Guid) || - propertyType == typeof(decimal)) - { - return false; - } - - // Enums are scalar - if (propertyType.IsEnum) - { - return false; - } - - // byte[] is scalar (used for binary data) - if (propertyType == typeof(byte[])) + // Primitives, enums, and well-known scalar types (string, dates, guid, decimal, byte[]) are scalar + if (propertyType.IsPrimitive || propertyType.IsEnum || _scalarTypes.Contains(propertyType)) { return false; } - // Collections of entities are navigation properties (but not string which is IEnumerable) - if (typeof(System.Collections.IEnumerable).IsAssignableFrom(propertyType) && - propertyType != typeof(string)) + // Collections are navigation properties (string, the one scalar IEnumerable, is already handled above) + if (typeof(System.Collections.IEnumerable).IsAssignableFrom(propertyType)) { return true; }