<?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>Ideas For Free &#187; C#</title>
	<atom:link href="http://blog.libinuko.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.libinuko.com</link>
	<description>Only freedom will grow our ideas</description>
	<lastBuildDate>Wed, 28 Jul 2010 14:55:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<!-- google ad injected by adsense-optimizer http://www.adsenseoptimizer.de -->
			<div  style="padding:7px; display: block; margin-left: auto; margin-right: auto; text-align: center;"><!-- Linkblock number: 1 --><script type="text/javascript"><!--
	 
google_ad_client = "pub-4105800609450516";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al_s"; google_ad_channel ="4111627870";
google_color_border = "8FC906";
google_color_bg = "F0F0F0";
google_color_link = "A6FF73";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>	<item>
		<title>Howto: Use lambda expression in SharePoint Object model</title>
		<link>http://blog.libinuko.com/2009/04/21/howto-use-lambda-expression-in-sharepoint-object-model/</link>
		<comments>http://blog.libinuko.com/2009/04/21/howto-use-lambda-expression-in-sharepoint-object-model/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 14:51:00 +0000</pubDate>
		<dc:creator>cakriwut</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://blog.libinuko.com/2009/04/21/howto-use-lambda-expression-in-sharepoint-object-model/</guid>
		<description><![CDATA[English Lambda expression has been introduced since .NET framework 3.5, it is an anonymous function that can contain statement and expression. For more understanding on lambda expression you can read directly in MSDN page here. I will assume that you have read the topic and you can remember the lambda simply as: (input parameters ) =&#62; operation We [...] <a href="http://blog.libinuko.com/2009/04/21/howto-use-lambda-expression-in-sharepoint-object-model/">[read more...]</a>]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><!-- google_ad_section_start --><p>English</p>
<p>Lambda expression has been introduced since .NET framework 3.5, it is an anonymous function that can contain statement and expression. For more understanding on lambda expression you can read directly in <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx">MSDN page here</a>. I will assume that you have read the topic and you can remember the lambda simply as:</p>
<blockquote><p>(input parameters ) =&gt; operation</p>
</blockquote>
<p>We will start with very basic operation of using lambda expression in SOM, and I hope you’ll find your path for more complex one. <em>(note some code may not be efficient, for the clarity purpose)</em></p>
<p>A.&#160; Start with OfType&lt;TResult&gt;() function to get IEnumerable that implement query pattern.</p>
<p>Example: </p>
<p>Originally to browse to all Site collection in WebApplication we will write,</p>
<blockquote><p>SPWebApplication webApplication = SPContext.Current.Site.WebApplication;</p>
<p><strong>SPSiteCollection allSPSite = webApplication.Sites;</strong></p>
<p><strong>foreach(SPSite spSite in allSPSite)</strong></p>
<p><strong>{</strong></p>
<p><strong>&#160;&#160;&#160;&#160;&#160; // operation in the SPSite</strong></p>
<p><strong>}</strong></p>
</blockquote>
<p>the equivalent for our lambda starter is,</p>
<blockquote><p>SPWebApplication webApplication = SPContext.Current.Site.WebApplication;</p>
<p><strong>var allSPSite = webApplication.Sites.OfType&lt;SPSite&gt;();</strong></p>
<p><strong>foreach(SPSite spSite in allSPSite)</strong></p>
<p><strong>{</strong></p>
<p><strong>&#160;&#160;&#160;&#160;&#160; // operation in the SPSite</strong></p>
<p><strong>}</strong></p>
</blockquote>
<p>B. Use lambda expression in the IEnumerable</p>
<p>Example :</p>
<p>You need to list all Site collection which uses STS site template.</p>
<p>Originally you will write,</p>
<blockquote><p>SPWebApplication webApplication = SPContext.Current.Site.WebApplication;</p>
<p><strong>SPSiteCollection allSPSite = webApplication.Sites;</strong></p>
<p><strong>foreach(SPSite spSite in allSPSite)</strong></p>
<p><strong>{</strong></p>
<p><strong>&#160;&#160;&#160;&#160;&#160; if(spSite.RootWeb.WebTemplate.Equals(“STS”,StringComparison.InvariantCultureIgnoreCase))</strong></p>
<p><strong>&#160;&#160;&#160;&#160; {</strong></p>
<p><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Do operation in selected site </strong></p>
<p><strong>&#160;&#160;&#160;&#160; }</strong></p>
<p><strong>}</strong></p>
</blockquote>
<p> the equivalent using lambda is,</p>
<blockquote><p>SPWebApplication webApplication = SPContext.Current.Site.WebApplication;</p>
<p><strong>var allSPSite = webApplication.Sites.OfType&lt;SPSite&gt;().Where(s =&gt; s.RootWeb.WebTemplate.Equals(&quot;STS&quot;, StringComparison.InvariantCultureIgnoreCase));</strong></p>
<p><strong>foreach(SPSite spSite in allSPSite)</strong></p>
<p><strong>{</strong></p>
<p><strong>&#160;&#160;&#160;&#160;&#160; // operation in the SPSite</strong></p>
<p><strong>}</strong></p>
</blockquote>
<p>Ok, now I believe you will get the idea of how to use lambda expression in SOM collection. In next posting, I’ll cover directly to the sample usage of the lambda.</p>
<!-- google_ad_section_end --><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://blog.libinuko.com/2009/04/21/howto-use-lambda-expression-in-sharepoint-object-model/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
