示例#1
0
        public static DataTable ListToDataTable(object datas, string tableName)
        {
            Type type = ZGeneric.GetGenericType(datas);

            if (string.IsNullOrEmpty(tableName))
            {
                tableName = type.Name;
            }

            DataTable table = new DataTable(tableName);

            table.BeginLoadData();

            var properties = ZReflection.GetProperties(type);

            foreach (var p in properties)
            {
                Type   colType  = p.Value.PropertyType;
                string typeName = colType.ToString();
                if (colType.IsGenericType)
                {
                    typeName = colType.GetGenericArguments()[0].ToString();
                }

                Type newType = Type.GetType(typeName, false);
                if (newType != null)
                {
                    table.Columns.Add(p.Value.Name, newType);
                }
            }

            IEnumerator enumerator = ((dynamic)datas).GetEnumerator();

            while (enumerator.MoveNext())
            {
                DataRow row = table.NewRow();
                foreach (var p in properties)
                {
                    var value = ZGeneric.GetValue(enumerator.Current, p.Value.Name);
                    if ((Type.GetType(p.Value.PropertyType.ToString(), false) != null) && (value != null))
                    {
                        row[p.Value.Name] = value;
                    }
                }
                table.Rows.Add(row);
            }
            table.EndLoadData();
            table.AcceptChanges();
            return(table);
        }
 private void InitProjectScriptNameList()
 {
     projectScriptList = ZReflection.GetTypeListExtendFrom(typeof(MonoBehaviour), true);
     Debug.Log("继承于MonoBehaviour的类数量:" + projectScriptList.Count);
 }