Beispiel #1
0
        /// <summary>
        /// Writes the record to the LTSV file.
        /// </summary>
        /// <typeparam name="T">The type of the record.</typeparam>
        /// <param name="record">The record to write.</param>
        public void WriteRecord <T>(T record)
        {
            Ensure.ArgumentNotNull(record, nameof(record));

            var classMap = _configuration.GetClassMap(typeof(T));

            foreach (var p in classMap.PropertyMaps)
            {
                var label       = p.LabelString;
                var value       = p.Getter(record);
                var valueString = p.TypeConverter.ConvertToString(value, this, p);
                WriteField(label, valueString);
            }

            NextRecord();
        }
Beispiel #2
0
        /// <summary>
        /// Gets the record coverted into <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The type of the record.</typeparam>
        /// <returns>The record converted to <typeparamref name="T"/>.</returns>
        public T GetRecord <T>()
        {
            CheckHasBeenRead();

            var classMap = _configuration.GetClassMap(typeof(T));
            var record   = (T)classMap.Constructor();

            foreach (var p in classMap.PropertyMaps)
            {
                if (_currentRecord.ContainsKey(p.LabelString))
                {
                    var field = GetField(p.LabelString);
                    var value = p.TypeConverter.ConvertFromString(field, this, p);
                    p.Setter(record, value);
                }
            }
            return(record);
        }