#c# #.net #servicestack #servicestack-text
#c# #.net #servicestack #servicestack-text
Вопрос:
Я пытаюсь использовать ServiceStack.Текст 5.13.2 для десериализации некоторых данных csv в список объектов, но он просто дает мне список объектов со значениями свойств Null. Вот PoC, который я собрал, может кто-нибудь сказать мне, почему это не работает? В настоящее время это таргетинг .СЕТЕВАЯ структура 4.8
using ServiceStack.Text; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ServerStackTextPOC { public class EmpReport { public string EmplAccountId; } class Program { static void Main(string[] args) { CsvConfiglt;EmpReportgt;.CustomHeadersMap = new Dictionarylt;string, stringgt; { {"Account Id", "EmplAccountId" } }; var csv = ""Account Id"rn"0013689""; var data = CsvSerializer.DeserializeFromStringlt;Listlt;EmpReportgt;gt;(csv); Console.WriteLine(data); Console.WriteLine(data[0]); //I'm expecting EmplAccountId to be 0013689 but it is null. Console.WriteLine(data[0].EmplAccountId); Console.ReadLine(); } } }
ОТРЕДАКТИРУЙТЕ, похоже, что он вообще не десериализуется. Приведенный ниже код также не работает. Мне интересно, может быть, я просто что-то упускаю..
using ServiceStack.Text; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ServerStackTextPOC { public class EmpReport { public string EmplAccountId; } public class EmpReport2 { public string EmplAccountId; } public class Program { public static void Main(string[] args) { CsvConfiglt;EmpReportgt;.CustomHeadersMap = new Dictionarylt;string, stringgt; { {"Account Id", "EmplAccountId" } }; var csv = ""Account Id"rn"0013689"rn"00224466""; var data = CsvSerializer.DeserializeFromStringlt;Listlt;EmpReportgt;gt;(csv); Console.WriteLine(data); Console.WriteLine(data[0]); //I'm expecting EmplAccountId to be 0013689 but it is null. Console.WriteLine(data[0].EmplAccountId); Console.ReadLine(); var csv2 = ""EmplAccountId"rn"00013689""; var data2 = CsvSerializer.DeserializeFromStringlt;Listlt;EmpReport2gt;gt;(csv2); Console.WriteLine(data2[0].EmplAccountId); Console.ReadLine(); csv2 = "EmplAccountIdrn0013689"; data2 = CsvSerializer.DeserializeFromStringlt;Listlt;EmpReport2gt;gt;(csv2); // even without the custom header. deserialization does not work. Console.WriteLine(data2[0].EmplAccountId); Console.ReadLine(); } } }
EDIT updated target framework to 4.8