private void AddValue(object classInstance, DataColumn dc) { //get the value object value = null; TypeInfo ti = _classType.GetTypeInfo(); PropertyInfo pi = ti.GetDeclaredProperty(dc.Field.Name); if (pi != null) { value = pi.GetValue(classInstance); } //add value if (dc.Field.IsArray) { IEnumerable ienum = value as IEnumerable; if (ienum != null) { dc.IncrementLevel(); foreach (object element in ienum) { dc.Add(element); } dc.DecrementLevel(); } } else { dc.Add(value); } }
public void Simple_repeated_field_write_read() { //v2 var ds = new DataSet( new DataField <int>("id"), new DataField <IEnumerable <string> >("items")); ds.Add(1, new[] { "one", "two" }); DataSet ds1 = ds.WriteRead(); Assert.Equal(1, ds1[0][0]); Assert.Equal(new[] { "one", "two" }, ds1[0][1]); //v3 // arrange var field = new DataField <IEnumerable <int> >("items"); var column = new DataColumn(field); column.IncrementLevel(); column.Add(1); column.Add(2); column.DecrementLevel(); column.IncrementLevel(); column.Add(3); column.Add(4); column.DecrementLevel(); // act DataColumn rc = WriteReadSingleColumn(field, 2, column); // assert Assert.Equal(new int[] { 1, 2, 3, 4 }, rc.DefinedData); Assert.Equal(new int[] { 1, 1, 1, 1 }, rc.DefinitionLevels); Assert.Equal(new int[] { 0, 1, 0, 1 }, rc.RepetitionLevels); }