'automapper pass profile as an method parameter
I have columns like this in excel :
| ProductID | SomeExplanation | AnotherColumn1 | AnotherColumn2 | AnotherColumn3 |
|---|---|---|---|---|
| 1 | X | 6 | A | 65465 |
| 2 | Y | 5 | B | 6556 |
| 3 | Z | 7 | C | 65465 |
I need to convert this excel to list of columns and these columns must be an dictonary. And the dicitonary must have key values (like ProductID,SomeExplanation,AnotherColumn1 ,AnotherColumn2 , AnotherColumn3 ) and list values(for exmaple ProductID key's values : 1,2,3).
I am using aspose library and I am taking values(every cells) as an object so I need an configuration file to convert this object type to spefic types like int,string,double etc.
.This is my method but It creating the values as an object :
public List<Dictionary<string, List<object>>> GenerateExcelDictionary(Worksheet worksheet)
{
var columnMax = worksheet.Cells.MaxDataColumn;
var rowMax = worksheet.Cells.MaxDataRow;
var myExcelContainer = new List<Dictionary<string, List<object>>>();
var columnKeyWithValues = new Dictionary<string, List<object>>(); // I want to use spefic types instead ofobject
for (int column = 0; column < columnMax; column++)
{
var columnName = worksheet.Cells[0, column].Value.ToString().Replace(" ", string.Empty);
columnKeyWithValues.Add(columnName, new List<object>());
}
for (int column = 0; column < columnMax; column++)
{
var values = new List<object>();
for (int row = 1; row < rowMax; row++)
{
values.Add(worksheet.Cells[row, column]);
}
columnKeyWithValues[worksheet.Cells[0, column].Value.ToString().Replace(" ", string.Empty)] = values;
}
myExcelContainer.Add(columnKeyWithValues);
return myExcelContainer;
}
in this method I am getting the column values as an object but I want to use more spefic type(like int, string,double).
So I need to somekind a mapper or generic type(I think both of them required) but I could not make.
My general question how to inform method the types that I want to create in List and with its key values. And how can I pass automapper configuration to method ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
