<?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>dotnet thoughts &#187; Reflection</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/reflection/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 03:18:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How find all the types implemented by an interface</title>
		<link>http://www.dotnetthoughts.net/2011/03/06/how-find-all-the-types-implemented-by-an-interface/</link>
		<comments>http://www.dotnetthoughts.net/2011/03/06/how-find-all-the-types-implemented-by-an-interface/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 14:46:20 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1564</guid>
		<description><![CDATA[Here is code snippet which helps to find all the types from an assembly, which is implemented from a specific interface. And here is the same which is implemented by lambda expressions. Happy Coding Related content: ArgumentException &#8211; This row &#8230; <a href="http://www.dotnetthoughts.net/2011/03/06/how-find-all-the-types-implemented-by-an-interface/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is code snippet which helps to find all the types from an assembly, which is implemented from a specific interface.</p>
<pre class="brush: csharp; title: ; notranslate">
var types = from type in Assembly.GetExecutingAssembly().GetTypes()
where typeof(IPlugin).IsAssignableFrom(type) &amp;&amp; !type.IsInterface
select type;
</pre>
<p>And here is the same which is implemented by lambda expressions.</p>
<pre class="brush: csharp; title: ; notranslate">
var types = Assembly.GetExecutingAssembly().GetTypes().Where
    ((type) =&gt; typeof(IPlugin).IsAssignableFrom(type));
</pre>
<p>Happy Coding <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2011/11/03/argumentexception-this-row-already-belongs-to-another-table/" title="Permanent link to ArgumentException &#8211; This row already belongs to another table">ArgumentException &#8211; This row already belongs to another table</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/07/02/fluent-email-library-for-c-using-dynamicobject/" title="Permanent link to Fluent email library for c# using DynamicObject">Fluent email library for c# using DynamicObject</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/11/18/how-to-create-a-rss-feed-using-asp-net/" title="Permanent link to How to create a RSS feed using ASP.Net">How to create a RSS feed using ASP.Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/26/how-to-return-null-from-a-generic-method/" title="Permanent link to How to return null from a generic method">How to return null from a generic method</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/01/30/finding-types-in-a-running-program/" title="Permanent link to Finding types in a Running Program">Finding types in a Running Program</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/03/06/how-find-all-the-types-implemented-by-an-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting and Setting properties on runtime using Reflectoion</title>
		<link>http://www.dotnetthoughts.net/2009/03/09/getting-and-setting-properties-on-runtime-using-reflectoion/</link>
		<comments>http://www.dotnetthoughts.net/2009/03/09/getting-and-setting-properties-on-runtime-using-reflectoion/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 09:02:26 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Properties]]></category>
		<category><![CDATA[Reflection]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://anuraj.wordpress.com/?p=250</guid>
		<description><![CDATA[In series of Reflection related posting this is the second post. You can see the post here. Now I am posting about Properties. We can set / read properties of Class using reflection. Setting Properties 1) For setting properties, we &#8230; <a href="http://www.dotnetthoughts.net/2009/03/09/getting-and-setting-properties-on-runtime-using-reflectoion/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In series of Reflection related posting this is the second post. You can see the post <a href="http://anuraj.wordpress.com/2009/01/30/finding-types-in-a-running-program/">here</a>. Now I am posting about Properties. We can set / read properties of Class using reflection.</p>
<p><strong>Setting Properties</strong></p>
<p>1) For setting properties, we enumerate all the properties using Type.GetProperties() method<br />
2) Then we will check, whether the property is readonly or not.<br />
3) Read the value(if the datatype of property and the datatype of the value you are trying to set, didn&#8217;t match it will throw some error.)<br />
4) If datatype is mismatching, convert the value to property data type using &#8220;Convert.ChangeType&#8221; *<br />
5) Call the PropertyInfo.SetValue method.</p>
<p>Here is the source code, here I am reading from Registry and Loads the required data in a class level variable.</p>
<pre class="brush: vb; title: ; notranslate">
Dim result As MyCustomClass
Dim PropertyValue As Object
Dim converter As New TypeConverter
For Each CurrentProperty As PropertyInfo In MyType.GetProperties
If CurrentProperty.CanWrite Then
PropertyValue = GetValue(CurrentProperty.Name)	'GetValue function retuns the value based on the parameter given.
If PropertyValue IsNot Nothing Then
	CurrentProperty.SetValue(result, Convert.ChangeType(PropertyValue, CurrentProperty.PropertyType), Nothing)
End If
End If
Next
</pre>
<p>* Convert.ChangeType &#8211; Works only with basic datatypes.</p>
<p>And for getting we will do almost reverse operation.<br />
<strong>Getting values from Property</strong></p>
<p>It is simple and strait forward, and here is the code</p>
<pre class="brush: vb; title: ; notranslate">
Dim propertyValue As String
For Each CurrentProperty As PropertyInfo In MyType.GetProperties
If CurrentProperty.CanRead Then
propertyValue = CurrentProperty.GetValue(MyCustomClass, Nothing).ToString
End If
Next
</pre>
<p>Happy Reflection.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2009/03/02/reading-pop3-mailbox-using-vbnet/" title="Permanent link to Reading POP3 mailbox using VB.Net">Reading POP3 mailbox using VB.Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/22/adding-and-reading-files-from-sql-server-2008-filestream/" title="Permanent link to Adding and Reading files from SQL Server 2008 Filestream">Adding and Reading files from SQL Server 2008 Filestream</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2008/05/08/using-iocompression-namespace/" title="Permanent link to Using IO.Compression namespace">Using IO.Compression namespace</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/03/09/getting-and-setting-properties-on-runtime-using-reflectoion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

