/// ¹¹Ô캯Êý public XDataReader(IDataReader dataReader) { string typeName = dataReader.GetSchemaTable().TableName; DynamicClass dynamicClass = new DynamicClass(typeName); for (int i = 0; i < dataReader.FieldCount; i++) { string fieldType = dataReader.GetFieldType(i).Name; string name = dataReader.GetName(i); dynamicClass.AddProperty(fieldType, name); this.columnNames.Add(name); } dynamicClass.CreateAssembly(); while (dataReader.Read()) { //object[] itemArray = new object[this.columnNames.Count]; object entity = dynamicClass.CreateInstance(); for (int i = 0; i < this.columnNames.Count; i++) { object value = dataReader.GetValue(i); DynamicClass.SetValue(entity, columnNames[i], value); } this.rows.Add(entity); } }
public void EvaluateDefinedClassVar() { ClassVarExpression expr = new ClassVarExpression("one"); DynamicClass cls = new DynamicClass(null); DynamicObject obj = new DynamicObject(cls); cls.SetValue("one", 1); Context context = new Context(obj, null); Assert.AreEqual(1, expr.Evaluate(context)); }