DataTableタイプオブジェクトをListコレクションに変換 2167 ワード J# namespace ChatRoom.Services.Utils { public static class ConvertUtils { /// <summary> /// DataTable List /// </summary> /// <param name="table"></param> /// <returns></returns> public static List<T> ConvertToList<T>(DataTable table) where T : new() { // List<T> list = null; if (table != null) { DataColumnCollection columns = table.Columns; int columnCount = columns.Count; T type = new T(); Type columnType = type.GetType(); PropertyInfo[] properties = columnType.GetProperties(); if (properties.Length == columnCount) { list = new List<T>(); foreach (DataRow currentRow in table.Rows) { for (int i = 0; i < columnCount; i++) { for (int j = 0; j < properties.Length; j++) { if (columns[i].ColumnName == properties[j].Name) { properties[j].SetValue(type, currentRow[i], null); } } } list.Add(type); type = new T(); } } else { list = null; } } else { throw new ArgumentNullException(" "); } return list; } } }効率性能はどうですか?? ファイルを書くfaster and faster Cocos2d-x3.2 EditBoxの使用