Exemple #1
0
        public static FieldAccessExpression <T> Create(string name, IConverterSpec converterSpec)
        {
            typeProperties.Value.TryGetValue(name, out var member);
            if (member == null)
            {
                if (typeof(IAdditionalColumns).IsAssignableFrom(typeof(T)))
                {
                    var type          = typeof(AdditionalColumnsAccessExpression <>);
                    var genericAccess = type.MakeGenericType(typeof(T));
                    var instance      = (FieldAccessExpression <T>)Activator.CreateInstance(genericAccess, name);
                    return(instance);
                }
                return(empty);
            }

            var extendedConverter = converterSpec as IExtendedConverterSpec;

            if (!converterSpec.HasConverter(member.PropertyType) && (extendedConverter == null || !extendedConverter.HasExtendedConverter(member.PropertyType)))
            {
                throw new ArgumentException($"Provided IConverterSpec doesn't implement conversion from string to {member.PropertyType}", nameof(converterSpec));
            }

            var generic = typeof(FieldAccessExpression <,>).MakeGenericType(typeof(T), member.PropertyType);

            return((FieldAccessExpression <T>)Activator.CreateInstance(generic, member, converterSpec));
        }
 public static IEnumerable <T> ReadAs <T>(IEnumerable <string> file, Func <T> creatorFunc, char separator = ',', IConverterSpec converter = null)
 {
     return(new FastCsvReader(file, separator, converter).ReadAsImpl <T>(creatorFunc));
 }
 /// <summary>
 /// Reads a csv file to an enumeration of type <typeparamref name="T"/>.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="file">The enumeration of strings representing the csv file.</param>
 /// <param name="separator">The separator character (default is ,)</param>
 /// <param name="converter">The type converter specification (default is null)</param>
 /// <returns>An enumeration of type <typeparamref name="T"/></returns>
 public static IEnumerable <T> ReadAs <T>(IEnumerable <string> file, char separator = ',', IConverterSpec converter = null)
     where T : new()
 {
     return(new FastCsvReader(file, separator, converter).ReadAsImpl <T>());
 }
 private FastCsvReader(IEnumerable <string> file, char separator = ',', IConverterSpec converter = null)
 {
     this.converter = converter ?? new DefaultConverterSpec();
     enumerator     = file.GetEnumerator();
     splitter       = new LineSplitter(separator);
 }
Exemple #5
0
 public LineAccess(string[] headerFields, IConverterSpec spec)
 {
     fields            = headerFields.Select(t => FieldAccessExpression <T> .Create(t, spec)).ToArray();
     this.headerFields = headerFields;
 }