<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>haslo.ch - Guido's Blog &#187; asp.net</title>
	<atom:link href="http://www.haslo.ch/blog/tag/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.haslo.ch/blog</link>
	<description>We believe that people with passion can change the world for the better.</description>
	<lastBuildDate>Wed, 16 Nov 2011 11:23:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>SetProperty and GetProperty with C# Reflection</title>
		<link>http://www.haslo.ch/blog/setproperty-and-getproperty-with-c-reflection/</link>
		<comments>http://www.haslo.ch/blog/setproperty-and-getproperty-with-c-reflection/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 12:32:29 +0000</pubDate>
		<dc:creator>haslo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.haslo.ch/blog/?p=2863</guid>
		<description><![CDATA[I&#8217;ll make a post soon, comparing Ruby on Rails to C# with ASP.NET MVC, but this here is atomic and might be of help for one or two readers. If you want to set and get properties in C# in a type-agnostic way, these are the functions you want to put into a library class [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll make a post soon, comparing Ruby on Rails to C# with ASP.NET MVC, but this here is atomic and might be of help for one or two readers.</p>
<p>If you want to set and get properties in C# in a type-agnostic way, these are the functions you want to put into a library class somewhere (or, as I did, into the class that uses them):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #FF0000;">object</span> getProperty<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> containingObject, <span style="color: #FF0000;">string</span> propertyName<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">return</span> containingObject.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InvokeMember</span><span style="color: #000000;">&#40;</span>propertyName, BindingFlags.<span style="color: #0000FF;">GetProperty</span>, <span style="color: #0600FF;">null</span>, containingObject, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> setProperty<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> containingObject, <span style="color: #FF0000;">string</span> propertyName, <span style="color: #FF0000;">object</span> newValue<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    containingObject.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">InvokeMember</span><span style="color: #000000;">&#40;</span>propertyName, BindingFlags.<span style="color: #0000FF;">SetProperty</span>, <span style="color: #0600FF;">null</span>, containingObject, <span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> newValue <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>That&#8217;s all I will say on this subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haslo.ch/blog/setproperty-and-getproperty-with-c-reflection/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

