com.alicizax.unity.framework/Runtime/ABase/Extension/System/EnumerableExtensions.cs

35 lines
1008 B
C#
Raw Normal View History

2025-10-11 15:18:09 +08:00
using System;
using System.Collections.Generic;
2026-03-23 19:10:57 +08:00
using System.Linq;
2025-10-11 15:18:09 +08:00
namespace AlicizaX
{
[UnityEngine.Scripting.Preserve]
2026-03-23 19:10:57 +08:00
public static class EnumerableExtensions
2025-10-11 15:18:09 +08:00
{
/// <summary>
2026-03-23 19:10:57 +08:00
/// 根据指定键进行去重。
2025-10-11 15:18:09 +08:00
/// </summary>
[UnityEngine.Scripting.Preserve]
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
var identifiedKeys = new HashSet<TKey>();
foreach (var item in source)
{
if (identifiedKeys.Add(keySelector(item)))
{
yield return item;
}
}
}
2026-03-23 19:10:57 +08:00
/// <summary>
/// 判断集合是否包含另一个集合中的所有元素。
/// </summary>
public static bool ContainsAll<T>(this IEnumerable<T> source, IEnumerable<T> values)
{
return !source.Except(values).Any();
}
2025-10-11 15:18:09 +08:00
}
}