{"action":"created","issue":{"url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/375","labels_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/375/labels{/name}","comments_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/375/comments","events_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/375/events","html_url":"https://github.com/JoshClose/CsvHelper/issues/375","id":70102193,"number":375,"title":"Can I map class properties at runtime in version 2.12.0.2 ?","user":{"login":"bilogik","id":12067026,"avatar_url":"https://avatars.githubusercontent.com/u/12067026?v=3","gravatar_id":"","url":"https://api.github.com/users/bilogik","html_url":"https://github.com/bilogik","followers_url":"https://api.github.com/users/bilogik/followers","following_url":"https://api.github.com/users/bilogik/following{/other_user}","gists_url":"https://api.github.com/users/bilogik/gists{/gist_id}","starred_url":"https://api.github.com/users/bilogik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bilogik/subscriptions","organizations_url":"https://api.github.com/users/bilogik/orgs","repos_url":"https://api.github.com/users/bilogik/repos","events_url":"https://api.github.com/users/bilogik/events{/privacy}","received_events_url":"https://api.github.com/users/bilogik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-22T11:32:06Z","updated_at":"2015-04-22T14:08:17Z","closed_at":null,"body":"Hi,\r\n\r\nI am trying to map class properties at runtime but I am unable to, the property map collection is not available to add etc., I tried following the steps mentioned in this  thread -  https://github.com/JoshClose/CsvHelper/issues/36\r\nbut I believe I am using a different version. (2.12.0.2). Is there any way that this can be done ?\r\n"},"comment":{"url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/comments/95192557","html_url":"https://github.com/JoshClose/CsvHelper/issues/375#issuecomment-95192557","issue_url":"https://api.github.com/repos/JoshClose/CsvHelper/issues/375","id":95192557,"user":{"login":"Orcomp","id":2459973,"avatar_url":"https://avatars.githubusercontent.com/u/2459973?v=3","gravatar_id":"","url":"https://api.github.com/users/Orcomp","html_url":"https://github.com/Orcomp","followers_url":"https://api.github.com/users/Orcomp/followers","following_url":"https://api.github.com/users/Orcomp/following{/other_user}","gists_url":"https://api.github.com/users/Orcomp/gists{/gist_id}","starred_url":"https://api.github.com/users/Orcomp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Orcomp/subscriptions","organizations_url":"https://api.github.com/users/Orcomp/orgs","repos_url":"https://api.github.com/users/Orcomp/repos","events_url":"https://api.github.com/users/Orcomp/events{/privacy}","received_events_url":"https://api.github.com/users/Orcomp/received_events","type":"User","site_admin":false},"created_at":"2015-04-22T14:08:17Z","updated_at":"2015-04-22T14:08:17Z","body":"Thanks.\r\nYou can use standard markdown syntax to highlight the code. (i.e. three back ticks).\r\n\r\nI will make some minor changes and send a pull request to Josh tomorrow.\r\n\r\nHere is what your code looks like using the markdown code block for C#:\r\n\r\n```C#\r\nDefaultCsvClassMap custCodeMap = new DefaultCsvClassMap();\r\nCsvClassMap CustomerMap;\r\n\r\n// mapping holds the Property - csv column mapping \r\nforeach (string key in mapping.Keys)\r\n{\r\n    string val = mapping[key].ToString();\r\n    if (!String.IsNullOrEmpty(val))\r\n    {\r\n        PropertyInfo dMember = Activator.CreateInstance(typeof(Customer)).GetType().GetProperty(key);\r\n        CsvPropertyMap newMap = new CsvPropertyMap(dMember);\r\n        newMap.Name(val);\r\n        custCodeMap.PropertyMaps.Add(newMap);\r\n    }\r\n}\r\n\r\nCustomerMap = custCodeMap;\r\ncsv.Configuration.RegisterClassMap(CustomerMap);\r\n```\r\n\r\nJust looking at your code more closely could you replace:\r\n\r\n```C#\r\nPropertyInfo dMember = Activator.CreateInstance(typeof(Customer)).GetType().GetProperty(key);\r\n```\r\n\r\nwith\r\n\r\n```C#\r\nPropertyInfo dMember = typeof(Customer).GetProperty(key);\r\n```\r\n\r\n\r\nOk decided to tweak the code now. Could you please check if this still works for you:\r\n\r\n```C#\r\nvar customerMap = new DefaultCsvClassMap();\r\n\r\n // mapping holds the Property - csv column mapping \r\n foreach (string key in mapping.Keys)\r\n{\r\n    var columnName = mapping[key].ToString();\r\n\r\n    if (!String.IsNullOrEmpty(columnName))\r\n    {\r\n         var propertyInfo = typeof(Customer).GetType().GetProperty(key);\r\n         var newMap = new CsvPropertyMap(propertyInfo);\r\n         newMap.Name(columnName);\r\n         customerMap.PropertyMaps.Add(newMap);\r\n     }\r\n}\r\n\r\ncsv.Configuration.RegisterClassMap(CustomerMap); // Might have to cast back to a CsvClassMap here.\r\n```\r\n"}}