public object CreateInstance(ObjectBuilderContext context) { if (!context.DataReaderAdapter.IsOpen) { context.DataReaderAdapter.Open(); } if (!context.DataReaderAdapter.IsReading) { if (!context.DataReaderAdapter.Read()) { if (!context.ResultType.IsValueType) { return(null); } throw new AdoExecutorException("Cannot read data from reader."); } } if (!context.DataReaderAdapter.IsClosed) { return(_objectConverter.ChangeType(context.ResultType, context.DataReaderAdapter.GetValue(context.DataReaderAdapter.CurrentColumnIndex))); } throw new AdoExecutorException("Cannot read data from reader."); }
private object CreateSingleInstance(IDataReaderAdapter dataReaderAdapter, Type instanceType) { var instance = Activator.CreateInstance(instanceType); var typeProperties = instanceType.GetProperties(BindingFlags.Public | BindingFlags.Instance); for (var i = 0; i < dataReaderAdapter.FieldCount; i++) { var columnName = dataReaderAdapter.GetName(i); var property = GetPropertyInfo(typeProperties, columnName); if (property != null) { var value = dataReaderAdapter.GetValue(i); var convertedValue = _objectConverter.ChangeType(property.PropertyType, value); property.SetValue(instance, convertedValue, null); } } return(instance); }