Exemplo n.º 1
0
        protected IEnumerable <T> ConvertDataToList <T>(TextReader tr)
        {
            IEnumerable <T> result    = new List <T>();
            CsvReader       csvReader = null;

            try
            {
                CsvHelper.Configuration.CsvConfiguration cnfg = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)
                {
                    HasHeaderRecord  = true,
                    IgnoreBlankLines = true,
                    TrimOptions      = CsvHelper.Configuration.TrimOptions.Trim
                };
                cnfg.RegisterClassMap(cnfg.AutoMap <T>());
                csvReader = new CsvReader(tr, cnfg);

                var list = csvReader.GetRecords <T>().ToList();
                result = list;
            }
            finally
            {
                if (csvReader != null)
                {
                    csvReader.Dispose();
                }
            }

            return(result);
        }
        public void CircularDependencyWithMultiplePropertiesTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
            var map    = config.AutoMap <A>();

            Assert.AreEqual(1, map.MemberMaps.Count);
            Assert.AreEqual(3, map.ReferenceMaps.Count);
        }
        public void CircularDependencyTest()
        {
            var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
            var map    = config.AutoMap <ACircular>();

            Assert.IsNotNull(map);
            Assert.AreEqual(1, map.MemberMaps.Count);
            Assert.AreEqual(1, map.ReferenceMaps.Count);
            Assert.AreEqual(1, map.ReferenceMaps[0].Data.Mapping.MemberMaps.Count);
            Assert.AreEqual(0, map.ReferenceMaps[0].Data.Mapping.ReferenceMaps.Count);
        }
 public void SelfCircularDependencyTest()
 {
     var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
     var map    = config.AutoMap <SelfCircularA>();
 }