<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: LINQ, SingleOrDefault and NullObject</title>
	<atom:link href="http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/</link>
	<description>Wrecks of code floating in the sea of Internet</description>
	<lastBuildDate>Wed, 28 Jul 2010 15:30:03 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: guest</title>
		<link>http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/comment-page-1/#comment-2528</link>
		<dc:creator>guest</dc:creator>
		<pubDate>Mon, 22 Jun 2009 17:42:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/#comment-2528</guid>
		<description>doesn&#039;t this work:

samples
   .Where(o =&gt; o.Name == &quot;someother&quot;)
   .DefaultIfEmpty(MyObject.NullValue)
   .Single()
   .Greet();</description>
		<content:encoded><![CDATA[<p>doesn&#8217;t this work:</p>
<p>samples<br />
   .Where(o =&gt; o.Name == &#8220;someother&#8221;)<br />
   .DefaultIfEmpty(MyObject.NullValue)<br />
   .Single()<br />
   .Greet();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Watson</title>
		<link>http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/comment-page-1/#comment-2025</link>
		<dc:creator>Thomas Watson</dc:creator>
		<pubDate>Mon, 12 Jan 2009 14:12:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/#comment-2025</guid>
		<description>Not sure how to post code here, because that didnt work! I will try this:

&quot; public static TSource SingleOrEmpty(this IEnumerable source, Func predicate)
        {
            var myNullObject = (TSource)Activator.CreateInstance(typeof(TSource));
            var myResult = source.SingleOrDefault(predicate);
            return myResult == null ? myNullObject : myResult;
        }&quot;</description>
		<content:encoded><![CDATA[<p>Not sure how to post code here, because that didnt work! I will try this:</p>
<p>&#8221; public static TSource SingleOrEmpty(this IEnumerable source, Func predicate)<br />
        {<br />
            var myNullObject = (TSource)Activator.CreateInstance(typeof(TSource));<br />
            var myResult = source.SingleOrDefault(predicate);<br />
            return myResult == null ? myNullObject : myResult;<br />
        }&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Watson</title>
		<link>http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/comment-page-1/#comment-2024</link>
		<dc:creator>Thomas Watson</dc:creator>
		<pubDate>Mon, 12 Jan 2009 14:06:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/#comment-2024</guid>
		<description>Hey, thanks for th start. Its annoying to have to create null objects this way, so I thought I would extend it with reflection:

public static TSource SingleOrEmpty(this IEnumerable source, Func predicate)
        {
            var myNullObject = (TSource)Activator.CreateInstance(typeof(TSource));
            var myResult = source.SingleOrDefault(predicate);
            return myResult == null ? myNullObject : myResult;
        }</description>
		<content:encoded><![CDATA[<p>Hey, thanks for th start. Its annoying to have to create null objects this way, so I thought I would extend it with reflection:</p>
<p>public static TSource SingleOrEmpty(this IEnumerable source, Func predicate)<br />
        {<br />
            var myNullObject = (TSource)Activator.CreateInstance(typeof(TSource));<br />
            var myResult = source.SingleOrDefault(predicate);<br />
            return myResult == null ? myNullObject : myResult;<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LINQ Master</title>
		<link>http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/comment-page-1/#comment-1692</link>
		<dc:creator>LINQ Master</dc:creator>
		<pubDate>Wed, 20 Aug 2008 14:03:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.codewrecks.com/blog/index.php/2008/08/20/linq-singleordefault-and-nullobject/#comment-1692</guid>
		<description>Great example. It sucks that we have to write our own overloads for the Default extensions. Maybe MS will fix this in the next version of LINQ.

&lt;a href=&quot;http://blog.linqexchange.com&quot; rel=&quot;nofollow&quot;&gt;LINQ Exchange - Learn LINQ and Lambda Expressions&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Great example. It sucks that we have to write our own overloads for the Default extensions. Maybe MS will fix this in the next version of LINQ.</p>
<p><a href="http://blog.linqexchange.com" rel="nofollow">LINQ Exchange &#8211; Learn LINQ and Lambda Expressions</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
