- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg) - LoginPanel: InputField placeholder本地化、字体颜色保持 - HistoryPanel: 用时数据本地化、placeholder本地化 - RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建) - AppraiseWindowBase: 评价等级本地化、操作消息重建 - EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized - StudentOperateRecorder: 新增InjectOperateMsgLocalized方法 - LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选 - 字体切换时保留颜色和verticalOverflow
220 lines
7.2 KiB
C#
220 lines
7.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
/// <summary>
|
||
/// 选择委托:从T【 学生】中选择某个属性 Key【Age】
|
||
/// 返回这个属性的值 20
|
||
/// </summary>
|
||
/// <typeparam name="T">数据类型:例如【 学生】</typeparam>
|
||
/// <typeparam name="Key">数据类型的属性:例如【Age,Tall】</typeparam>
|
||
/// <param name="t">数据类型的对象:例如【 张三】</param>
|
||
/// <returns>数据类型的属性的值</returns>
|
||
public delegate Key SelectHandler<T,Key>(T t);
|
||
/// <summary>
|
||
/// 查找委托
|
||
/// </summary>
|
||
/// <typeparam name="T">数据类型</typeparam>
|
||
/// <param name="t">数据类型的对象</param>
|
||
/// <returns>返回bool值</returns>
|
||
public delegate bool FindHandler<T>(T t);//
|
||
/// <summary>
|
||
/// 数组助手类:工具类 提供通用方法,调用方便
|
||
/// </summary>
|
||
public class ArrayHelper
|
||
{
|
||
/// <summary>
|
||
///1. 通用的升序排序的方法
|
||
/// </summary>
|
||
/// <typeparam name="T">数据类型:例如【 学生】</typeparam>
|
||
/// <typeparam name="Key">数据类型的属性:例如【Age,Tall】</typeparam>
|
||
/// <param name="arr">数据类型的数组:例如【很多学生】</param>
|
||
/// <param name="handler">选择委托:例如
|
||
/// 从学生张三中选择某个属性 Age,返回这个属性的值 20</param>
|
||
/// <returns>升序排序的结果</returns>
|
||
public static T[] OrderBy<T,Key>(T[] arr,
|
||
SelectHandler<T,Key> handler )
|
||
where Key:IComparable,IComparable<Key>
|
||
{
|
||
for (int i = 0; i < arr.Length - 1; i++)
|
||
{
|
||
for (int j = i + 1; j < arr.Length; j++)
|
||
{
|
||
//if (arr[i].CompareTo(arr[j]) > 0)
|
||
if(handler(arr[i]).CompareTo(handler(arr[j]))>0)
|
||
{
|
||
T temp = arr[j];
|
||
arr[j] = arr[i];
|
||
arr[i] = temp;
|
||
}
|
||
}
|
||
}
|
||
return arr;
|
||
}
|
||
/// <summary>
|
||
///2. 通用的降序排序的方法
|
||
/// </summary>
|
||
/// <typeparam name="T">数据类型:例如【 学生】</typeparam>
|
||
/// <typeparam name="Key">数据类型的属性:例如【Age,Tall】</typeparam>
|
||
/// <param name="arr">数据类型的数组:例如【很多学生】</param>
|
||
/// <param name="handler">选择委托:例如
|
||
/// 从学生张三中选择某个属性 Age,返回这个属性的值 20</param>
|
||
/// <returns>升序排序的结果</returns>
|
||
public static T[] OrderByDescending<T, Key>(T[] arr,
|
||
SelectHandler<T, Key> handler)
|
||
where Key : IComparable, IComparable<Key>
|
||
{
|
||
for (int i = 0; i < arr.Length - 1; i++)
|
||
{
|
||
for (int j = i + 1; j < arr.Length; j++)
|
||
{
|
||
//if (arr[i].CompareTo(arr[j]) > 0)
|
||
if (handler(arr[i]).CompareTo(handler(arr[j])) < 0)
|
||
{
|
||
T temp = arr[j];
|
||
arr[j] = arr[i];
|
||
arr[i] = temp;
|
||
}
|
||
}
|
||
}
|
||
return arr;
|
||
}
|
||
/// <summary>
|
||
/// 3. 通用的找最大的方法
|
||
/// </summary>
|
||
/// <typeparam name="T">数据类型</typeparam>
|
||
/// <typeparam name="Key">数据类型的属性</typeparam>
|
||
/// <param name="arr">数据类型的集合</param>
|
||
/// <param name="handler">选择委托</param>
|
||
/// <returns></returns>
|
||
public static T Max<T, Key>(T[] arr,
|
||
SelectHandler<T, Key> handler)
|
||
where Key : IComparable, IComparable<Key>
|
||
{
|
||
T temp = arr[0];
|
||
for (int i = 1; i < arr.Length ; i++)
|
||
{
|
||
if (handler(temp).CompareTo(handler(arr[i])) < 0)
|
||
{
|
||
temp = arr[i];
|
||
}
|
||
}
|
||
return temp;
|
||
}
|
||
/// <summary>
|
||
/// 4. 通用的找最小的方法
|
||
/// </summary>
|
||
/// <typeparam name="T">数据类型</typeparam>
|
||
/// <typeparam name="Key">数据类型的属性</typeparam>
|
||
/// <param name="arr">数据类型的集合</param>
|
||
/// <param name="handler">选择委托</param>
|
||
/// <returns></returns>
|
||
public static T Min<T, Key>(T[] arr,
|
||
SelectHandler<T, Key> handler)
|
||
where Key : IComparable, IComparable<Key>
|
||
{
|
||
T temp = arr[0];
|
||
for (int i = 1; i < arr.Length; i++)
|
||
{
|
||
if (handler(temp).CompareTo(handler(arr[i])) > 0)
|
||
{
|
||
temp = arr[i];
|
||
}
|
||
}
|
||
return temp;
|
||
}
|
||
/// <summary>
|
||
/// 查找Find,按照某个条件去查找,返回满足条件的一个
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="arr"></param>
|
||
/// <param name="handler"></param>
|
||
/// <returns></returns>
|
||
public static T Find<T>(T[] arr, FindHandler<T> handler)
|
||
{
|
||
for (int i = 0; i < arr.Length; i++)
|
||
{
|
||
if (handler(arr[i]))
|
||
{
|
||
return arr[i];
|
||
}
|
||
}
|
||
return default(T);
|
||
}
|
||
//查找所有FindAll、,按照某个条件去查找,返回满足条件的所有的。
|
||
public static T[] FindAll<T>(T[] arr, FindHandler<T> handler)
|
||
{
|
||
List<T> list=new List<T>();
|
||
for (int i = 0; i < arr.Length; i++)
|
||
{
|
||
if (handler(arr[i]))
|
||
{ list.Add(arr[i]);}
|
||
}
|
||
return list.ToArray();
|
||
}
|
||
//从集合的每个对象提取某个属性的值 组成一个新的数组 // Select 多个学生 学生的成绩【60,70,50,100】
|
||
public static Key[] Select<T,Key>(T[] arr, SelectHandler<T, Key> handler)
|
||
{
|
||
Key[] keys = new Key[arr.Length];
|
||
for (int i=0;i<arr.Length;i++)
|
||
{
|
||
keys[i] = handler(arr[i]);
|
||
}
|
||
return keys;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 遍历集合A 取出未在集合B中出现过的元素
|
||
/// </summary>
|
||
/// <typeparam name="T">类型</typeparam>
|
||
/// <param name="listA">待遍历查找的集合</param>
|
||
/// <param name="listB">待排除元素的集合</param>
|
||
/// <returns>不存在的值</returns>
|
||
public static List<T> GetAny<T>(List<T> listA, List<T> listB)
|
||
{
|
||
List<T> anyT = new List<T>();
|
||
for (int i = 0; i < listA.Count; i++)
|
||
{
|
||
if (!listB.Contains(listA[i]))
|
||
anyT.Add(listA[i]);
|
||
}
|
||
return anyT;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查找Find,按照某个条件去查找,返回满足条件的一个
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="arr"></param>
|
||
/// <param name="handler"></param>
|
||
/// <returns></returns>
|
||
public static T Find<T>(List<T> arr, FindHandler<T> handler)
|
||
{
|
||
for (int i = 0; i < arr.Count; i++)
|
||
{
|
||
if (handler(arr[i]))
|
||
{
|
||
return arr[i];
|
||
}
|
||
}
|
||
return default(T);
|
||
}
|
||
|
||
public static T Min<T, Key>(List<T> arr,
|
||
SelectHandler<T, Key> handler)
|
||
where Key : IComparable, IComparable<Key>
|
||
{
|
||
T temp = arr[0];
|
||
for (int i = 1; i < arr.Count; i++)
|
||
{
|
||
if (handler(temp).CompareTo(handler(arr[i])) > 0)
|
||
{
|
||
temp = arr[i];
|
||
}
|
||
}
|
||
return temp;
|
||
}
|
||
|
||
//........添加
|
||
}
|
||
|