Skip to content

Commit

Permalink
Support net8.0 - Avoid evaluating Current on an empty enumerator (#2974
Browse files Browse the repository at this point in the history
…) (#2988)

* Avoid evaluating Current on an empty enumerator

* Don't use an iterator when an indexer is available

Co-authored-by: Larry Ewing <lewing@microsoft.com>
  • Loading branch information
habbes and lewing authored May 31, 2024
1 parent 9eef76b commit 2bc99f9
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/Microsoft.OData.Core/UriParser/ODataPathInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@ internal class ODataPathInfo

public ODataPathInfo(ODataPath odataPath)
{
ODataPathSegment lastSegment = odataPath.LastSegment;
ODataPathSegment previous = null;
var segs = odataPath.GetEnumerator();
int count = 0;
while (++count < odataPath.Count && segs.MoveNext())
{
}
ODataPathSegment targetSegment = odataPath.LastSegment;

previous = segs.Current;
if (lastSegment != null)
if (targetSegment != null)
{
// use previous segment if the last one is Key or Count Segment
if (lastSegment is KeySegment || lastSegment is CountSegment)
// use next to last segment if the last one is Key or Count Segment
if (targetSegment is KeySegment || targetSegment is CountSegment)
{
lastSegment = previous;
if (odataPath.Count > 1)
{
targetSegment = odataPath.Segments[odataPath.Count - 2];
}
}

this.targetNavigationSource = lastSegment.TargetEdmNavigationSource;
this.targetEdmType = lastSegment.EdmType;
this.targetNavigationSource = targetSegment.TargetEdmNavigationSource;
this.targetEdmType = targetSegment.EdmType;
if (this.targetEdmType != null)
{
IEdmCollectionType collectionType = this.targetEdmType as IEdmCollectionType;
Expand Down

0 comments on commit 2bc99f9

Please sign in to comment.