Ejemplo n.º 1
0
        public static IEnumerable <PropertyInfo> OrderByProperty(Type type)
        {
            var propertyInfos = type.GetProperties()
                                .Where(x => x.CustomAttributes.Any(y => y.AttributeType == typeof(DataMemberAttribute)))
                                .Select(x => new { PropertyInfo = x, Order = CsvSerializerHelpers.GetDataMemberOffset(x) })
                                .OrderBy(x => x.Order)
                                .ThenBy((x => x.PropertyInfo.Name))
                                .Select(x => x.PropertyInfo)
                                .ToArray();

            return(propertyInfos);
        }
Ejemplo n.º 2
0
        public IEnumerable <DelimitedColumn> GetDelimitedColumns()
        {
            foreach (var propertyInfo in CsvSerializerHelpers.OrderByProperty(this.type))
            {
                var delimitedColumn = new DelimitedColumn()
                {
                    Name = propertyInfo.Name,
                    Type = propertyInfo.PropertyType,
                };

                yield return(delimitedColumn);
            }
        }
Ejemplo n.º 3
0
        public CsvSerializer()
        {
            this.type          = typeof(T);
            this.propertyInfos = CsvSerializerHelpers.OrderByProperty(this.type)
                                 .ToArray();

            this.propertySetters = this.propertyInfos.Select(CoercionHelpers.CreatePropertySetter <T>)
                                   .ToArray();

            if (!this.IsDataContract())
            {
                string message = $@"The type ""{this.type.FullName}"" does not have the [DataContract] attribute!";
                throw new ArgumentException(message);
            }
        }