Exemple #1
0
        public static RecordsReaderCacheEntry Create(IRecordsReader recordsReader)
        {
            var recordsReaderCacheEntry = new RecordsReaderCacheEntry();

            if (!recordsReader.HasRecords)
            {
                return(recordsReaderCacheEntry);
            }

            var enumerator = recordsReader.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var currentItem = enumerator.Current;
                if (!recordsReaderCacheEntry.FieldNames.Any())
                {
                    var fieldNameLookup = GetPrivateFieldValue(currentItem, "_fieldNameLookup");
                    recordsReaderCacheEntry.FieldNames = (string[])GetPrivateFieldValue(fieldNameLookup, "_fieldNames");
                }

                var currentRecordDictionary = new Dictionary <string, object>();

                var values = (object[])GetPrivateFieldValue(currentItem, "_values");

                foreach (var fieldName in recordsReaderCacheEntry.FieldNames)
                {
                    var valueIndex = Array.IndexOf(recordsReaderCacheEntry.FieldNames, fieldName);
                    var value      = values[valueIndex];
                    if (value is DBNull)
                    {
                        value = null;
                    }

                    currentRecordDictionary.Add(fieldName, value);
                }

                recordsReaderCacheEntry.Records.Add(currentRecordDictionary);
            }

            return(recordsReaderCacheEntry);
        }