Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions PanoramicData.OData.Client/MemberPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ internal static bool TryGetPathLoose(Expression expression, out string path)
return false;
}

/// <summary>
/// Well-known scalar (non-navigation) reference/value types that aren't caught by
/// <see cref="Type.IsPrimitive"/> or <see cref="Type.IsEnum"/>.
/// </summary>
private static readonly HashSet<Type> _scalarTypes =
[
typeof(string),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(DateOnly),
typeof(TimeOnly),
typeof(TimeSpan),
typeof(Guid),
typeof(decimal),
typeof(byte[])
];

/// <summary>
/// Determines if a property is a navigation property (vs a scalar property).
/// Navigation properties are entity references or collections of entities.
Expand All @@ -162,40 +179,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<char>)
if (typeof(System.Collections.IEnumerable).IsAssignableFrom(propertyType) &&
propertyType != typeof(string))
// Collections are navigation properties (string, the one scalar IEnumerable, is already handled above)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Nitpick: The comment mentions only string, but byte[] is also a scalar IEnumerable now handled by the _scalarTypes check at line 156.

Suggested change
// Collections are navigation properties (string, the one scalar IEnumerable, is already handled above)
// Collections are navigation properties (string and byte[], which are scalar IEnumerables, are already handled above)

if (typeof(System.Collections.IEnumerable).IsAssignableFrom(propertyType))
{
return true;
}
Expand Down