<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bommannan R on Medium]]></title>
        <description><![CDATA[Stories by Bommannan R on Medium]]></description>
        <link>https://medium.com/@bommannan.ra?source=rss-57b2ad62ad73------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vt97smhtk3sgiVzb4cxXlg.jpeg</url>
            <title>Stories by Bommannan R on Medium</title>
            <link>https://medium.com/@bommannan.ra?source=rss-57b2ad62ad73------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 21:32:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bommannan.ra/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Set Object Property via Reflection in C# (utilising property config)]]></title>
            <link>https://medium.com/@bommannan.ra/set-object-property-via-reflection-in-c-utilising-property-config-beef17fd3df3?source=rss-57b2ad62ad73------2</link>
            <guid isPermaLink="false">https://medium.com/p/beef17fd3df3</guid>
            <dc:creator><![CDATA[Bommannan R]]></dc:creator>
            <pubDate>Tue, 23 May 2023 16:41:55 GMT</pubDate>
            <atom:updated>2023-05-23T16:41:55.692Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently have come across a situation where property mapping is needed and the value to object properties should be set based on the mapping. Created a simple one and thought of sharing it and may be useful to someone who is looking for.</p><pre>Program.cs<br><br>using PropertyHandler;<br>using Newtonsoft.Json.Linq;<br>using System.Reflection;<br><br>string jsonString = &quot;{\n  \&quot;employee_id\&quot;: 1,\n  \&quot;employeename\&quot;: \&quot;ram\&quot;,\n  \&quot;dob\&quot;: \&quot;12-12-2012\&quot;,\n  \&quot;exp\&quot;:3\n}&quot;;<br>JObject json = JObject.Parse(jsonString);<br><br>string propertyFile = &quot;./PropMapper.cfg&quot;;<br><br>Employee e = new Employee();<br>var settingdata = Utility.LoadConfig(propertyFile);<br><br>foreach (KeyValuePair&lt;string, string&gt; entry in settingdata)<br>{<br>    Type type = e.GetType();<br>    PropertyInfo prop = type.GetProperty(entry.Key);<br>    if (prop.PropertyType == typeof(string))<br>    {<br>        prop.SetValue(e, json[entry.Value].ToString(), null);<br>    } else if (prop.PropertyType == typeof(int))<br>    {<br>        int tmp = int.Parse(json[entry.Value].ToString());<br>        prop.SetValue(e, tmp, null);<br>    }<br>}<br><br>Console.WriteLine(e.ToString());</pre><pre>Employee.cs<br><br>using System;<br>using System.Xml.Linq;<br><br>namespace PropertyHandler {<br> public class Employee {<br>  public int id { get; set; }<br>  public string name { get; set; }<br>  public string dob { get; set; }<br>  public int exp { get; set; }<br><br>        public override string ToString() {<br>            return &quot;Id: &quot; + id + &quot;, name: &quot; + name + &quot; ,dob: &quot; + dob + &quot;,exp: &quot; + exp;<br>        }<br>    }<br>}</pre><pre>Utility.cs<br><br>using System;<br>namespace PropertyHandler {<br> public class Utility {<br>        public static Dictionary&lt;string, string&gt; LoadConfig(string settingfile) {<br>            var dic = new Dictionary&lt;string, string&gt;();<br><br>            if (File.Exists(settingfile)) {<br>                var settingdata = File.ReadAllLines(settingfile);<br>                for (var i = 0; i &lt; settingdata.Length; i++) {<br>                    var setting = settingdata[i];<br>                    var sidx = setting.IndexOf(&quot;=&quot;);<br>                    if (sidx &gt;= 0) {<br>                        var skey = setting.Substring(0, sidx);<br>                        var svalue = setting.Substring(sidx + 1);<br>                        if (!dic.ContainsKey(skey)) {<br>                            dic.Add(skey, svalue);<br>                        }<br>                    }<br>                }<br>            }<br>            return dic;<br>        }<br>    }<br>}</pre><pre>PropMapper.cfg<br><br>id=employee_id<br>name=employeename<br>dob=dob<br>exp=exp</pre><p>PropMapper.cfg has the property mapping which helps to map real world objects into internal object model. Credits to the .NET reflection</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beef17fd3df3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>