1
考慮下面的類:使用ServiceStack.Text反序列化CSV與CustomHeaders:不工作?
class Foo {
public string bar { get; set; }
public string rab { get; set; }
public override string ToString()
{
return string.Format("[Foo bar={0}, rab={1}]", bar, rab);
}
}
而下面的代碼:
var csv1 =
"bar,rab" + Environment.NewLine +
"a,b" + Environment.NewLine +
"c,d" + Environment.NewLine +
"e,f" + Environment.NewLine;
var csv2 =
"xbar,xrab" + Environment.NewLine +
"a,b" + Environment.NewLine +
"c,d" + Environment.NewLine +
"e,f" + Environment.NewLine;
Console.WriteLine(CsvSerializer.DeserializeFromString<List<Foo>>(csv1).First());
CsvConfig<TMDBEntity>.CustomHeadersMap = new Dictionary<string, string> {
{"bar", "xbar"},
{"rab", "xrab"}
};
Console.WriteLine(CsvSerializer.DeserializeFromString<List<Foo>>(csv2).First());
它是打印:
[Foo bar=a, rab=b]
[Foo bar=, rab=]
,而我希望它打印
[Foo bar=a, rab=b]
[Foo bar=a, rab=b]
爲什麼不使用xbar和xrab拾取自定義標題?
ServiceStack.Text版本4.5.14.0
有一個類似的帖子:https://stackoverflow.com/questions/36851708/deserialize-csv-with -customheaders - 使用 - servicestack文本。 statci CsvConfig對象將字典寫入CsvWriter和CsvReader ,嘗試使用「CcvConfig .CustomHeadersMap = ....」作爲示例。如果不使用TMDBEntity的頭部 –