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); }
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); } }
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); } }