示例#1
0
        static ObservableList <T> PopulateObservableList <T>(CSVMap map)
        {
            ObservableList <T> list = new ObservableList <T>();

            bool hasInfo = false;
            int  index   = 0;

            for (index = 0; index < map.Contents.Count; index++)
            {
                T obj = Activator.CreateInstance <T>();

                hasInfo = PopulateObject <T>(map.Contents[index], ref obj);

                if (hasInfo)
                {
                    if (LogInfo)
                    {
                        Debug.Log(obj.ToString());
                    }

                    list.Add(obj);
                }
            }

            return(list);
        }
示例#2
0
        public static IEnumerator GenerateListAsync <T>(string filePath, Action <List <T> > callback)
        {
            CSVMap   map  = new CSVMap(filePath);
            List <T> list = new List <T>();

            string header = "";

            System.Type  type = typeof(T);
            PropertyInfo info = null;

            PropertyInfo[] properties = type.GetProperties();

            for (int index = 0; index < map.Contents.Count; index++)
            {
                T obj = Activator.CreateInstance <T>();

                for (int sub = 0; sub < properties.Length; sub++)
                {
                    info = properties[sub];

                    header = "";

                    object[] att = info.GetCustomAttributes(typeof(CSVColumn), false);

                    if (att.Length > 0)
                    {
                        header = (att[0] as CSVColumn).Name;
                        if (map.Headers.Contains(header))
                        {
                            info.SetValue(obj, Convert.ChangeType(map.Contents[index].GetField(header), info.PropertyType), null);
                        }
                    }
                }

                if (LogInfo)
                {
                    Debug.Log(obj.ToString());
                }

                list.Add(obj);

                yield return(null);
            }

            if (callback != null)
            {
                callback(list);
            }
        }