public IEnumerator GetEnumerator()
 {
     if (_dataSet.Tables.Count == 1 && _dataSet.Tables[0].Columns.Count == 1 && _dataSet.Tables[0].Rows.Count == 1)
         // scalar
     {
         yield return _dataSet.Tables[0].Rows[0][0];
     }
     else
     {
         foreach (DataTable table in _dataSet.Tables)
         {
             var properties = new List<Pair<string, Type>>();
             foreach (DataColumn column in table.Columns)
             {                        
                 properties.Add(new Pair<string, Type>(column.ColumnName, column.DataType));
             }
             var t = new DataTypeBuilder("Pscx").CreateType(properties);
             foreach (DataRow row in table.Rows)
             {
                 var target = Activator.CreateInstance(t);
                 new PropertySetter(t).SetValues(target, new DataRowIndexer(row), false);
                 yield return target;
             }
         }
     }
 }
 public IEnumerator GetEnumerator()
 {
     if (_dataSet.Tables.Count == 1 && _dataSet.Tables[0].Columns.Count == 1 && _dataSet.Tables[0].Rows.Count == 1)
     // scalar
     {
         yield return(_dataSet.Tables[0].Rows[0][0]);
     }
     else
     {
         foreach (DataTable table in _dataSet.Tables)
         {
             var properties = new List <Pair <string, Type> >();
             foreach (DataColumn column in table.Columns)
             {
                 properties.Add(new Pair <string, Type>(column.ColumnName, column.DataType));
             }
             var t = new DataTypeBuilder("Pscx").CreateType(properties);
             foreach (DataRow row in table.Rows)
             {
                 var target = Activator.CreateInstance(t);
                 new PropertySetter(t).SetValues(target, new DataRowIndexer(row), false);
                 yield return(target);
             }
         }
     }
 }
Beispiel #3
0
 public void CreateType_MultipleInvocationsReturnDifferentTypes()
 {
     var dt1 = new Pair<string, Type>[0];
     var dt2 = new Pair<string, Type>[0];
     var builder = new DataTypeBuilder("PowerSQL");
     var lhs = builder.CreateType(dt1);
     var rhs = builder.CreateType(dt2);
     Assert.AreNotEqual(lhs, rhs);
 }
Beispiel #4
0
 public void CreateType_AddsPropertiesForDataTableColumns()
 {
     var dt = new Pair<string, Type>[1];
     dt[0] = new Pair<string, Type>("Test", typeof(int));
     var builder = new DataTypeBuilder("PowerSQL");
     var dynamic = builder.CreateType(dt);
     var properties = dynamic.GetProperties(BindingFlags.Public | BindingFlags.Instance);
     Assert.AreEqual(1, properties.Length);
     Assert.AreEqual("Test", properties[0].Name);
     Assert.AreEqual( typeof (int?), properties[0].PropertyType);
 }
Beispiel #5
0
 public void CreateType_ReturnsNewType()
 {
     var builder = new DataTypeBuilder("PscxDb");
     Type type = builder.CreateType(new Pair<string, Type>[0]);
     Assert.IsNotNull(type);
 }