/// <summary> /// Populate missing or incomplete properties from model metadata. /// </summary> /// <param name="fieldInfo">The <c>ExcelColumnInfoCollection</c> to populate.</param> /// <param name="itemType">The type of item whose metadata this is being populated from.</param> /// <param name="data">The collection of values being serialised. (Not used, provided for use by derived /// types.)</param> protected virtual void PopulateFieldInfoFromMetadata(ExcelColumnInfoCollection fieldInfo, Type itemType, IEnumerable <object> data) { // Populate missing attribute information from metadata. var metadata = _modelMetadataProvider.GetMetadataForType(itemType); if (metadata != null && metadata.Properties != null) { foreach (var modelProp in metadata.Properties) { var propertyName = modelProp.PropertyName; if (!fieldInfo.Contains(propertyName)) { continue; } var field = fieldInfo[propertyName]; var attribute = field.ExcelAttribute; if (!field.IsExcelHeaderDefined) { field.Header = modelProp.DisplayName ?? propertyName; } if (attribute != null && attribute.UseDisplayFormatString) { field.FormatString = modelProp.DisplayFormatString; } } } }