Skip to content

Commit

Permalink
Merge pull request #19252 from unoplatform/dev/xygu/20250116/depobjco…
Browse files Browse the repository at this point in the history
…l-index-out-range

fix: align DepObjCol indexer behavior with winui
  • Loading branch information
Xiaoy312 authored Jan 17, 2025
2 parents d5463a8 + 3268696 commit 10a90f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ObjectiveC;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -28,4 +29,16 @@ public void When_Add_Multiple_And_Invoke()

Assert.IsTrue(list.SequenceEqual(["One", "Two"]));
}

[TestMethod]
public void When_Indexer_Get_IndexOutOfRange()
{
Assert.IsNull(new DependencyObjectCollection()[int.MaxValue]);
}

[TestMethod]
public void When_Indexer_Get_NegativeIndex()
{
Assert.ThrowsException<ArgumentOutOfRangeException>(() => new DependencyObjectCollection()[-1]);
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/DependencyObjectCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private protected virtual void ValidateItem(T item) { }

public T this[int index]
{
get => _list[index];
get => index < _list.Count ? _list[index] : default;
set
{
ValidateItem(value);
Expand Down

0 comments on commit 10a90f8

Please sign in to comment.