<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/visual-basic/tags/Reflection</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Sat, 25 May 2013 20:58:56 GMT</pubDate>
<item>
<title>(Visual Basic) Reflection extension method to copy properties from one object to another object. - s0lidmetal</title>
<link>http://snipplr.com/view/36094/reflection-extension-method-to-copy-properties-from-one-object-to-another-object/</link>
<description><![CDATA[ <p>This copies all property values from Class A to Class B. Useful if you have many unrelated classes that share similar properties and you are constantly writing code like:

    shirt.Color = pants.Color
    shirt.Pattern = pants.Pattern
    shirt.Style = pants.Style

Could change to:

    pants.CopyPropertiesTo(shirt)</p> ]]></description>
<pubDate>Thu, 24 Jun 2010 05:12:30 GMT</pubDate>
<guid>http://snipplr.com/view/36094/reflection-extension-method-to-copy-properties-from-one-object-to-another-object/</guid>
</item>
<item>
<title>(Visual Basic) Reflection extension method to bind DataRow values to object properties. - s0lidmetal</title>
<link>http://snipplr.com/view/36093/reflection-extension-method-to-bind-datarow-values-to-object-properties/</link>
<description><![CDATA[ <p>This will populate object properties with values from a DataRow. The DataTable column names must match the property names and types of the target class.

Example:

    DataTable dt = new DataTable();
    dt.Columns.Add("TestString", typeof(string));
    dt.Columns.Add("TestBool", typeof(bool));
    dt.Columns.Add("TestInt", typeof(int));
    dt.Columns.Add("TestDouble", typeof(double));
    dt.Columns.Add("TestDecimal", typeof(decimal));
    dt.Columns.Add("TestFloat", typeof(string));

    DataRow dr = dt.NewRow();
    dr["TestString"] = "Hello";
    dr["TestBool"] = false;
    dr["TestInt"] = DBNull.Value;
    dr["TestDouble"] =4.56;
    dr["TestDecimal"] = 7.89m;
    dr["TestFloat"] = "3.14f";
    dt.Rows.Add(dr);

    TestClass tc = new TestClass();
    dr.AssignObjectValue(tc);
            
    class TestClass
    {
        public string TestString { get; set; }
        public bool? TestBool { get; set; }
        public int? TestInt { get; set; }
        public double TestDouble { get; set; }
        public decimal TestDecimal { get; set; }
        public float TestFloat { get; set; }
    }</p> ]]></description>
<pubDate>Thu, 24 Jun 2010 05:04:11 GMT</pubDate>
<guid>http://snipplr.com/view/36093/reflection-extension-method-to-bind-datarow-values-to-object-properties/</guid>
</item>
</channel>
</rss>