Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions src/Appium.Net/Appium/MobileBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindsByFluentSelector<IWebElement> finder)
return finder.FindElements(_searchingCriteriaName, selector).ToList().AsReadOnly();
return finder.FindElements(_searchingCriteriaName, selector).AsReadOnly();
throw new InvalidCastException($"Unable to cast {context.GetType().FullName} " +
Comment on lines 57 to 61
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

After replacing .ToList().AsReadOnly() with .AsReadOnly(), this file no longer appears to use any LINQ extensions. using System.Linq; at the top of MobileBy.cs can likely be removed to avoid an unused-using warning.

Copilot uses AI. Check for mistakes.
$"to {nameof(IFindsByFluentSelector<IWebElement>)}");
}
Expand Down Expand Up @@ -157,7 +157,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindByAccessibilityId<IWebElement> finder)
return finder.FindElementsByAccessibilityId(selector).ToList().AsReadOnly();
return finder.FindElementsByAccessibilityId(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -198,7 +198,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindByAndroidUIAutomator<IWebElement> finder)
return finder.FindElementsByAndroidUIAutomator(selector).ToList().AsReadOnly();
return finder.FindElementsByAndroidUIAutomator(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -230,7 +230,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindByAndroidDataMatcher<IWebElement> finder)
return finder.FindElementsByAndroidDataMatcher(selector).ToList().AsReadOnly();
return finder.FindElementsByAndroidDataMatcher(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -262,7 +262,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindByAndroidViewMatcher<IWebElement> finder)
return finder.FindElementsByAndroidViewMatcher(selector).ToList().AsReadOnly();
return finder.FindElementsByAndroidViewMatcher(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -290,7 +290,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindByWindowsUIAutomation<IWebElement> finder)
return finder.FindElementsByWindowsUIAutomation(selector).ToList().AsReadOnly();
return finder.FindElementsByWindowsUIAutomation(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -318,7 +318,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindByTizenUIAutomation<IWebElement> finder)
return finder.FindElementsByTizenUIAutomation(selector).ToList().AsReadOnly();
return finder.FindElementsByTizenUIAutomation(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -346,7 +346,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindsByIosNSPredicate<IWebElement> finder)
return finder.FindElementsByIosNsPredicate(selector).ToList().AsReadOnly();
return finder.FindElementsByIosNsPredicate(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -374,7 +374,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindsByIosClassChain<IWebElement> finder)
return finder.FindElementsByIosClassChain(selector).ToList().AsReadOnly();
return finder.FindElementsByIosClassChain(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down Expand Up @@ -402,7 +402,7 @@ public override IWebElement FindElement(ISearchContext context)
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (context is IFindsByImage<IWebElement> finder)
return finder.FindElementsByImage(selector).ToList().AsReadOnly();
return finder.FindElementsByImage(selector).AsReadOnly();
return base.FindElements(context);
}

Expand Down
19 changes: 19 additions & 0 deletions src/Appium.Net/Appium/ReadOnlyCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Comment on lines +1 to +4
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

using System; is unused in this new file; removing it avoids compiler warnings and keeps the usings minimal.

Copilot uses AI. Check for mistakes.

namespace OpenQA.Selenium.Appium
{
internal static class ReadOnlyCollectionExtensions
{
public static ReadOnlyCollection<T> AsReadOnly<T>(this IReadOnlyCollection<T> collection)
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

ReadOnlyCollectionExtensions is internal, so this public method is effectively internal anyway. Consider making the method internal as well to reflect its intended visibility and avoid confusing API surface expectations inside the assembly.

Suggested change
public static ReadOnlyCollection<T> AsReadOnly<T>(this IReadOnlyCollection<T> collection)
internal static ReadOnlyCollection<T> AsReadOnly<T>(this IReadOnlyCollection<T> collection)

Copilot uses AI. Check for mistakes.
{
if (collection is ReadOnlyCollection<T> readOnlyCollection)
{
return readOnlyCollection;
}
return new ReadOnlyCollection<T>(collection as IList<T> ?? collection.ToList());
}
}
}
Loading