Ejemplo n.º 1
0
        public static DataPopulator Build(Type entityType)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException(nameof(entityType));
            }

            var properties = entityType
                             .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                             .Where(p => p.CanWrite)
                             .OrderBy(p => p.Name)
                             .ToArray();

            if (properties == null || properties.Length == 0)
            {
                return(null);
            }

            var populator = new DataPopulator(entityType)
            {
                _names   = new string[properties.Length],
                _setters = new Action <object, IDataRecord, int> [properties.Length],
            };

            for (int i = 0; i < properties.Length; i++)
            {
                populator._names[i]   = properties[i].Name;
                populator._setters[i] = DataEmitter.GenerateSetter(entityType, properties[i]);
            }

            return(populator);
        }
Ejemplo n.º 2
0
        public static void TestReadAssetsWithEmitting(int count, bool outputEnabled = false)
        {
            var populator = DataPopulator.Build(typeof(Models.Asset));

            Stopwatch stopwach = null;

            if (outputEnabled)
            {
                stopwach = new Stopwatch();
                stopwach.Restart();
            }

            using (var reader = GetReader("Asset", count))
            {
                var entities = populator.Populate(reader);

                foreach (var entity in entities)
                {
                    //if(outputEnabled)
                    //	Console.WriteLine(entity);
                }
            }

            if (outputEnabled)
            {
                stopwach.Stop();

                Console.WriteLine($"动态组装 {count} 条数据实体耗时 {stopwach.ElapsedMilliseconds} 毫秒。");
            }
        }