Updated the code..
public class UpdateProductTemplate
{
[Index(0)]
public string ProductID { get; set; }
[Index(2)]
public string ProductName { get; set; }
[Index(3)]
public string ShortDescription { get; set; }
}
public class UpdateProductTemplateWithPrice: UpdateProductTemplate
{
// For PRICE Updates!
[Index(4)]
public double? SitePrice { get; set; }
[Index(5)]
public double? ListPrice { get; set; }
[Index(6)]
public double? WebSitePrice { get; set; }
}
List<UpdateProductTemplateWithPrice> Products = new List<UpdateProductTemplateWithPrice>() {
new UpdateProductTemplateWithPrice
{
ProductID = "123",
ProductName = "Test Product",
ShortDescription = "Test",
SitePrice = 123.00,
ListPrice = 123.00,
WebSitePrice = 123.00
}
};
Type type = products.ToArray()[0].GetType();
PropertyInfo[] properties = type.GetProperties();
for (int i = 0; i < properties.Length; i++)
{
var cell = headerRow.CreateCell(i);
cell.SetCellValue(properties[i].Name);
}
When I do GetProperties()
, it ends up with the SitePrice
first on the array. I don't want that I want ProductID
to be first in the properties array...
I already did placed a higher index value in the child class, and expected ProductID
to be first when I do GetProperties()
, but it didn't.
based on the question and sample, created a simple Index attribute as below.
I think the simplest answer would be to call the Sort method with a custom comparer. Like this:
That will return the properties in the expected order.