{"action":"created","issue":{"url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/545","repository_url":"https://api.github.com/repos/JoshClose/CsvHelper","labels_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/545/labels{/name}","comments_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/545/comments","events_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/545/events","html_url":"https://github.com/JoshClose/CsvHelper/issues/545","id":165174786,"number":545,"title":"Runtime map with class containing readonly public properties and single ctor with all public properties","user":{"login":"jcasale","id":9957114,"avatar_url":"https://avatars.githubusercontent.com/u/9957114?v=3","gravatar_id":"","url":"https://api.github.com/users/jcasale","html_url":"https://github.com/jcasale","followers_url":"https://api.github.com/users/jcasale/followers","following_url":"https://api.github.com/users/jcasale/following{/other_user}","gists_url":"https://api.github.com/users/jcasale/gists{/gist_id}","starred_url":"https://api.github.com/users/jcasale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcasale/subscriptions","organizations_url":"https://api.github.com/users/jcasale/orgs","repos_url":"https://api.github.com/users/jcasale/repos","events_url":"https://api.github.com/users/jcasale/events{/privacy}","received_events_url":"https://api.github.com/users/jcasale/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-12T20:37:34Z","updated_at":"2016-07-13T16:12:35Z","closed_at":null,"body":"I am trying to parse records and create objects for a class which I create a runtime map for using operator supplied values for csv column to property names. The class only has public getters, all parameters must be supplied in the ctor. What options do I have to use such a class?"},"comment":{"url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/comments/232405618","html_url":"https://github.com/JoshClose/CsvHelper/issues/545#issuecomment-232405618","issue_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/545","id":232405618,"user":{"login":"JoshClose","id":114971,"avatar_url":"https://avatars.githubusercontent.com/u/114971?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshClose","html_url":"https://github.com/JoshClose","followers_url":"https://api.github.com/users/JoshClose/followers","following_url":"https://api.github.com/users/JoshClose/following{/other_user}","gists_url":"https://api.github.com/users/JoshClose/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshClose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshClose/subscriptions","organizations_url":"https://api.github.com/users/JoshClose/orgs","repos_url":"https://api.github.com/users/JoshClose/repos","events_url":"https://api.github.com/users/JoshClose/events{/privacy}","received_events_url":"https://api.github.com/users/JoshClose/received_events","type":"User","site_admin":false},"created_at":"2016-07-13T16:12:35Z","updated_at":"2016-07-13T16:12:35Z","body":"Currently, I don't think there is a way to do it. There is a `ConstructUsing` mapping, but you don't get anything from the row in it to pass into the constructor. That may be something I can add in the future.\r\n\r\nWhat you can do is this.\r\n\r\n```cs\r\nvoid Main()\r\n{\r\n\tusing (var stream = new MemoryStream())\r\n\tusing (var reader = new StreamReader(stream))\r\n\tusing (var writer = new StreamWriter(stream))\r\n\tusing (var csv = new CsvReader(reader))\r\n\t{\r\n\t\twriter.WriteLine(\"Id,Name\");\r\n\t\twriter.WriteLine(\"1,one\");\r\n\t\twriter.WriteLine(\"2,two\");\r\n\t\twriter.Flush();\r\n\t\tstream.Position = 0;\r\n\t\r\n\t\tcsv.Configuration.IgnorePrivateAccessor = true;\r\n\t\tcsv.Configuration.RegisterClassMap<TestMap>();\r\n\t\tvar records = csv.GetRecords<Test>().ToList().Dump();\r\n\t}\r\n}\r\n\r\npublic class Test\r\n{\r\n\tpublic int Id { get; private set; }\r\n\r\n\tpublic string Name { get; private set; }\r\n\r\n\tprivate Test() {}\r\n\r\n\tpublic Test(int id, string name)\r\n\t{\r\n\t\tId = id;\r\n\t\tName = name;\r\n\t}\r\n}\r\n\r\npublic class TestMap : CsvClassMap<Test>\r\n{\r\n\tpublic TestMap()\r\n\t{\r\n\t\tMap(m => m.Id);\r\n\t\tMap(m => m.Name);\r\n\t}\r\n}\r\n```\r\n\r\nThe default constructor can be private, and it works. If for some reason you can't use a default constructor, you could use the `ConstructUsing` mapping and just pass in defaults."}}
{"actor":{"display_login":"JoshClose"}}