// Get the properties that have the attribute
var attrProps = modelType.GetProperties().Where(x => Attribute.IsDefined(x, typeof(/*Attribute*/))).ToList();
// Add the property name and the attribute value
var columns = new Dictionary<string, string>();
foreach (var prop in attrProps)
{
var attr = (/*Attribute*/)prop.GetCustomAttributes(typeof(/*Attribute*/), false).FirstOrDefault();
columns.Add(prop.Name, attr./*Attribute property*/);
}
// Attribute Example
public class XcelHeaderAttribute : Attribute
{
public XcelHeaderAttribute(string headerName)
{
this.HeaderName = headerName;
}
public string HeaderName { get; set; }
}
// Property example
[XcelHeader("Твърда сума")]
public decimal hard_price { get; set; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter