<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>A Simple LINQ Example with System.Reflection and System.Drawing.Color</title><link>http://blogs.msdn.com/saveenr/archive/2008/08/04/a-simple-linq-example-with-system-reflection.aspx</link><description>Recently I needed to get see all the RGB values for the System.Drawing.Color values (for example System.Drawing.Color.Red, System.Drawing.Color.Aqua, etc.). It's a very simple task that shows some of the expressive simplicity of LINQ. Here's the sample</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: A Simple LINQ Example with System.Reflection and System.Drawing.Color</title><link>http://blogs.msdn.com/saveenr/archive/2008/08/04/a-simple-linq-example-with-system-reflection.aspx#8832099</link><pubDate>Mon, 04 Aug 2008 23:40:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8832099</guid><dc:creator>Jim Wooley</dc:creator><description>&lt;p&gt;With LINQ, one of the ways to know that there may be an additional optimization you could make is to see if you have any foreach iterations in your code. In your case, you can be a bit more declaritive as follows:&lt;/p&gt;
&lt;p&gt;var color_type = typeof(System.Drawing.Color);&lt;/p&gt;
&lt;p&gt;var color_properties = from prop in color_type.GetProperties()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where prop.PropertyType == color_type&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; let color = (System.Drawing.Color)prop.GetValue(null, null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; let rgb_int = (uint)color.ToArgb() &amp;amp; (0x00ffffff)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select new { prop, color, rgb_int };&lt;/p&gt;
&lt;p&gt;color_properties.ToList().ForEach(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;item =&amp;gt; Console.WriteLine(&amp;quot; {0} = ({1},{2},{3}) = 0x{4:X00000000}&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item.prop.Name, item.color.R, item.color.G, item.color.B, item.rgb_int));&lt;/p&gt;</description></item><item><title>re: A Simple LINQ Example with System.Reflection and System.Drawing.Color</title><link>http://blogs.msdn.com/saveenr/archive/2008/08/04/a-simple-linq-example-with-system-reflection.aspx#8832189</link><pubDate>Tue, 05 Aug 2008 00:35:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8832189</guid><dc:creator>saveenr</dc:creator><description>&lt;p&gt;Even better, thanks Jim!&lt;/p&gt;
</description></item></channel></rss>