Esempio n. 1
0
 public static CsvRow[] From <T>(IEnumerable <T> elements, Action <CsvRow.ICsvRowBuilderConfiguration> configure = null)
 {
     if (elements == null)
     {
         throw new ArgumentNullException("elements");
     }
     PropertyInfo[] array = (
         from x in (IEnumerable <PropertyInfo>) typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public)
         where x.CanRead
         select x).ToArray <PropertyInfo>();
     CsvRow.ICsvRowBuilder csvRowBuilder = CsvRow.BeginRows((
                                                                from x in (IEnumerable <PropertyInfo>) array
                                                                select x.Name).ToArray <string>());
     if (configure != null)
     {
         csvRowBuilder.Configure(configure);
     }
     foreach (T element in elements)
     {
         csvRowBuilder.Add((
                               from x in array
                               select x.GetValue(element)).Select <object, string>((object x) => {
             if (x == null)
             {
                 return(null);
             }
             return(x.ToString());
         }).ToArray <string>());
     }
     return(csvRowBuilder.End().ToRows());
 }
        public void Create_Csv_Add_Using_Mapper_Wrong_Header_Throws()
        {
            CsvRow.ICsvRowBuilder csv = CsvRow.BeginRows("Name");

            KeyNotFoundException exception =
                Assert.Throws <KeyNotFoundException>(() => csv.AddUsingMapper(x => x.Map("Age", "30")));

            Assert.That(exception.Message, Does.Contain("Age"));
        }