コード例 #1
0
        private static ZObject ParseItem(Type type, CsvRow row, TypeAccessor accessor, string typeName, Type parent = null)
        {
            object obj = Activator.CreateInstance(type);

            if (typeName == null)
            {
                typeName = type.GetName();
            }

            foreach (PropertyInfo property in type.GetCachedProperties())
            {
                string name = property.GetMappingName(typeName) + "." + property.GetName();
                if (property.Name == "Id" && !row.ContainsKey(name))
                {
                    continue;
                }
                if (!row.ContainsKey(name))
                {
                    continue;
                }

                string value = row[name];
                if (property.Name == "Id" && string.IsNullOrEmpty(value))
                {
                    return(null);
                }
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                SetProperty(obj, value, property, accessor);
            }

            ParseRelations((ZObject)obj, type, row, accessor, parent);

            return((ZObject)obj);
        }
コード例 #2
0
        internal static T ParseItem <T>(Type type, CsvRow row, TypeAccessor accessor, bool retrieveRelated)
            where T : ZObject
        {
            T      obj      = Activator.CreateInstance <T>();
            string typeName = type.GetMappingName();

            foreach (PropertyInfo property in type.GetCachedProperties())
            {
                string name = property.GetMappingName(typeName) + "." + property.GetName();
                if (!row.ContainsKey(name) || string.IsNullOrEmpty(row[name]))
                {
                    continue;
                }
                SetProperty(obj, row[name], property, accessor);
            }

            if (retrieveRelated)
            {
                ParseRelations(obj, type, row, accessor);
            }

            return(obj);
        }