Automapper Pass配置文件作为方法参数
我在excel中有类似的列:
productid | soming shose | shothercolumn1 | 另一个column2 | 另一个column3 |
---|---|---|---|---|
1 | x | 6 | a | 65465 |
2 | y | 5 | b | 6556 |
3 | z | 7 | c | 65465 |
我需要将此excel转换为列列表,这些列必须是命令。并且dicitonary必须具有钥匙值(例如productid,somesexplanation,shote -column1,othercolumn2,又有column3)和列表值(对于exmaple productid key的值:1,2,3)。
我正在使用aspose库,并且我将值(每个单元格)作为对象,因此我需要一个配置文件将此对象类型转换为诸如int,string,double等的小问题类型
。这是我的方法,但是它将值创建为一个对象:
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;
}
在此方法中,我将列值作为对象获得,但我想使用更多的spefic类型(例如int,string,double)。
因此,我需要某种映射器或通用类型(我认为它们都需要),但我无法做到。
我的一般问题如何告知方法我想在列表中创建的类型及其关键值。以及如何将自动应用程序配置传递给方法?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论