2021-02-20 12:52:35 +03:00
|
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
2021-02-24 22:35:37 +03:00
|
|
|
|
using Microsoft.UI.Xaml;
|
2021-02-20 12:52:35 +03:00
|
|
|
|
|
2021-03-19 01:31:02 +03:00
|
|
|
|
namespace CommunityToolkit.WinUI.UI.Predicates
|
2021-02-20 12:52:35 +03:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An <see cref="IPredicate{T}"/> type matching <see cref="FrameworkElement"/> instances by name.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal readonly struct PredicateByName : IPredicate<FrameworkElement>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of the element to look for.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly string name;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The comparison type to use to match <see name="name"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly StringComparison comparisonType;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="PredicateByName"/> struct.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name of the element to look for.</param>
|
|
|
|
|
/// <param name="comparisonType">The comparison type to use to match <paramref name="name"/>.</param>
|
|
|
|
|
public PredicateByName(string name, StringComparison comparisonType)
|
|
|
|
|
{
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.comparisonType = comparisonType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public bool Match(FrameworkElement element)
|
|
|
|
|
{
|
|
|
|
|
return element.Name.Equals(this.name, this.comparisonType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|