最近項目中用到個Linq的排序,由於沒有注冊適配器,導致不能用,其實ILRT作者已經做得很好,報錯代碼中已經做好對應的提示,只需要直接把提示的注冊代碼放到ILHelper.cs中注冊適配器的位置就好,以下是對應代碼的應用
熱更中的表格類
// 定義類
namespace ETHotfix
{
public class DailyTaskData
{
public int id { get; set; }
public string name { get; set; }
public int sort { get; set; }
public int type { get; set; }
public int sub_type { get; set; }
public long need_num { get; set; }
public string target { get; set; }
public string reward { get; set; }
public string description { get; set; }
public string uitype { get; set; }
}
} |
調用的地方,任意選擇一種排序方式,當前按照sort字段進行升序排序
// 定義類
List listDailyTask = new List();
listDailyTask.Sort(delegate (DailyTaskData x, DailyTaskData y)
{
return x.sort.CompareTo(y.sort);
});
listDailyTask = listDailyTask.OrderBy(u => u.sort).ToList(); |
從報錯提示賦值到ILHelper.cs中的注冊適配器的代碼
// 定義類
appDomain.DelegateManager.RegisterFunctionDelegate<ILTypeInstance, ILTypeInstance, Int32>();
appDomain.DelegateManager.RegisterDelegateConvertor<Comparison>((act) =>
{
return new Comparison((x, y) =>
{
return ((Func<ILTypeInstance, ILTypeInstance, Int32>)act)(x, y);
});
});
appDomain.DelegateManager.RegisterFunctionDelegate<ILTypeInstance, System.Int32>(); |
然后就可以正常使用排序了
