Skip to content

Commit

Permalink
fix: align DepObjCol indexer behavior with winui
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Jan 17, 2025
1 parent 18bcfb6 commit 3268696
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 3268696

Please sign in to comment.