Automapper Pass配置文件作为方法参数

发布于 2025-01-21 11:23:27 字数 1922 浏览 1 评论 0原文

我在excel中有类似的列:

productidsoming shoseshothercolumn1另一个column2另一个column3
1x6a65465
2y5b6556
3z7c65465

我需要将此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 :

ProductIDSomeExplanationAnotherColumn1AnotherColumn2AnotherColumn3
1X6A65465
2Y5B6556
3Z7C65465

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文