ET中熱更(ILRuntime)使用過程中,需要做的適配器,比如Linq排序 By Flamesky
最近項目中用到個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>(); |
然後就可以正常使用排序了
本文固定鏈接: http://www.flamesky.xyz/?p=30
轉載請註明: Flamesky 2018年05月31日 於 Flamesky 發表