<?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: Interesting Extension Hack To Get Around NullReferenceException&#8217;s</title>
	<atom:link href="http://www.coderjournal.com/index.php/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/</link>
	<description>while(!(succeed = try()));</description>
	<pubDate>Tue, 06 Jan 2009 09:23:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: eKnacks</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-23980</link>
		<dc:creator>eKnacks</dc:creator>
		<pubDate>Thu, 11 Dec 2008 04:53:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-23980</guid>
		<description>You've been knacked. Keep up the good work.</description>
		<content:encoded><![CDATA[<p>You&#8217;ve been knacked. Keep up the good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Berardi</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-4178</link>
		<dc:creator>Nick Berardi</dc:creator>
		<pubDate>Sat, 26 Apr 2008 20:44:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-4178</guid>
		<description>I am glad to see everybody is enjoying this.</description>
		<content:encoded><![CDATA[<p>I am glad to see everybody is enjoying this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop - April 25, 2008 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-4041</link>
		<dc:creator>Dew Drop - April 25, 2008 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Fri, 25 Apr 2008 13:00:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-4041</guid>
		<description>[...] Interesting Extension Hack to Get Around NullReferenceExceptions (Nick Berardi) [...]</description>
		<content:encoded><![CDATA[<p>[...] Interesting Extension Hack to Get Around NullReferenceExceptions (Nick Berardi) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Berardi</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-4040</link>
		<dc:creator>Nick Berardi</dc:creator>
		<pubDate>Fri, 25 Apr 2008 12:47:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-4040</guid>
		<description>Alvin,
You are right, I really didn't optimize my code, it was more for an example.

Erik,
That is pretty proprietary from the standpoint that the compiler would have to generate a dictionary to just hold the property if it was integrated into the language.

Andemann,
That is not quite how extension methods work.  NULL is an absence of an object, so you wouldn't be able to tell the object to response with String.Empty since the object isn't really there.</description>
		<content:encoded><![CDATA[<p>Alvin,<br />
You are right, I really didn&#8217;t optimize my code, it was more for an example.</p>
<p>Erik,<br />
That is pretty proprietary from the standpoint that the compiler would have to generate a dictionary to just hold the property if it was integrated into the language.</p>
<p>Andemann,<br />
That is not quite how extension methods work.  NULL is an absence of an object, so you wouldn&#8217;t be able to tell the object to response with String.Empty since the object isn&#8217;t really there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alvin Ashcraft</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-4037</link>
		<dc:creator>Alvin Ashcraft</dc:creator>
		<pubDate>Fri, 25 Apr 2008 12:41:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-4037</guid>
		<description>Good idea for a handy extension method. How about this tweak to your 'if' condition:

if (String.IsNullOrEmpty(s))
    return s;

Just a thought to save a Trim() operation if the string is already empty.

Thanks!</description>
		<content:encoded><![CDATA[<p>Good idea for a handy extension method. How about this tweak to your &#8216;if&#8217; condition:</p>
<p>if (String.IsNullOrEmpty(s))<br />
    return s;</p>
<p>Just a thought to save a Trim() operation if the string is already empty.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #81</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-4003</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #81</dc:creator>
		<pubDate>Fri, 25 Apr 2008 07:30:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-4003</guid>
		<description>[...] Interesting Extension Hack To Get Around NullReferenceException’s - Nick Berardi shows an interesting use of extension methods to help work round problems with te code bloat associated with checking nuls before you call methods. [...]</description>
		<content:encoded><![CDATA[<p>[...] Interesting Extension Hack To Get Around NullReferenceException’s - Nick Berardi shows an interesting use of extension methods to help work round problems with te code bloat associated with checking nuls before you call methods. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-3974</link>
		<dc:creator>Erik</dc:creator>
		<pubDate>Fri, 25 Apr 2008 04:55:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-3974</guid>
		<description>@Nick: "Where would you store this value" - I've seen some extension method "properties" use this pattern:

private static Dictionary _Tags = new Dictionary();

public static void set_Tag(this object taggedObject, object tag)
{
    if(taggedObject == null) return;
    if(_Tags.ContainsKey(taggedObject) &#38;&#38; tag == null) _Tags.Remove(taggedObject);
    _Tags[taggedObject] = tag;
}

public static object get_Tag(this object taggedObject)
{
    if(!_Tags.ContainsKey(taggedObject)) return null;
    return _Tags[taggedObject];
}

Of course this solution doesn't take into account objects that go out of scope; memory leaks will occur, although WeakReference could help here. This still doesn't get you property syntax in 3.5, even though it looks like it should.

ps: I hope the indentations work...</description>
		<content:encoded><![CDATA[<p>@Nick: &#8220;Where would you store this value&#8221; - I&#8217;ve seen some extension method &#8220;properties&#8221; use this pattern:</p>
<p>private static Dictionary _Tags = new Dictionary();</p>
<p>public static void set_Tag(this object taggedObject, object tag)<br />
{<br />
    if(taggedObject == null) return;<br />
    if(_Tags.ContainsKey(taggedObject) &amp;&amp; tag == null) _Tags.Remove(taggedObject);<br />
    _Tags[taggedObject] = tag;<br />
}</p>
<p>public static object get_Tag(this object taggedObject)<br />
{<br />
    if(!_Tags.ContainsKey(taggedObject)) return null;<br />
    return _Tags[taggedObject];<br />
}</p>
<p>Of course this solution doesn&#8217;t take into account objects that go out of scope; memory leaks will occur, although WeakReference could help here. This still doesn&#8217;t get you property syntax in 3.5, even though it looks like it should.</p>
<p>ps: I hope the indentations work&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andemann</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-3971</link>
		<dc:creator>Andemann</dc:creator>
		<pubDate>Fri, 25 Apr 2008 04:46:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-3971</guid>
		<description>Why not just extend the entire string object to return string.Emtpy if the value is null?

Your tryTrim should return string.empty and not the input value when the input value is null, that way you'll avoid a nullreferenceexception when you attempt to use the trimmed value</description>
		<content:encoded><![CDATA[<p>Why not just extend the entire string object to return string.Emtpy if the value is null?</p>
<p>Your tryTrim should return string.empty and not the input value when the input value is null, that way you&#8217;ll avoid a nullreferenceexception when you attempt to use the trimmed value</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Berardi</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-3872</link>
		<dc:creator>Nick Berardi</dc:creator>
		<pubDate>Thu, 24 Apr 2008 18:26:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-3872</guid>
		<description>You use to be able to hack your own properties in to classes so that you could change the visibility of them, but this was back in 1.0 and they corrected it in 1.1 and then introduced visibility to the properties in 2.0.  However I wonder would would happen in this case.

public static void set_MyProperty(this string s)...

If it compiled you should be able to do:
string s = "";
s.MyProperty = value;

However there seems to be a whole host of problems with making property extensions that is not currently dealt with in the .NET framework yet.

How would you set the value inside the object the get_ and set_ methods are static and outside of the object.  Where would you store this value, because remember the property is static and any property thing you would set would be the same across all properties for that method.  Which would become confusing since it looks like a property of the object.  

I am sure they will work it out, but probably not till 4.0 or 4.5.</description>
		<content:encoded><![CDATA[<p>You use to be able to hack your own properties in to classes so that you could change the visibility of them, but this was back in 1.0 and they corrected it in 1.1 and then introduced visibility to the properties in 2.0.  However I wonder would would happen in this case.</p>
<p>public static void set_MyProperty(this string s)&#8230;</p>
<p>If it compiled you should be able to do:<br />
string s = &#8220;&#8221;;<br />
s.MyProperty = value;</p>
<p>However there seems to be a whole host of problems with making property extensions that is not currently dealt with in the .NET framework yet.</p>
<p>How would you set the value inside the object the get_ and set_ methods are static and outside of the object.  Where would you store this value, because remember the property is static and any property thing you would set would be the same across all properties for that method.  Which would become confusing since it looks like a property of the object.  </p>
<p>I am sure they will work it out, but probably not till 4.0 or 4.5.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.coderjournal.com/2008/04/interesting-extension-hack-to-get-around-nullreferenceexceptions/comment-page-1/#comment-3867</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Thu, 24 Apr 2008 17:53:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.coderjournal.com/?p=216#comment-3867</guid>
		<description>That is awesome.  I wondered what would happen in these cases.  I'm starting to use extension methods more and more to ease common coding tasks.  I'm glad to see I can refactor my null checks into the extension methods themselves.  Now if we can only get extension properties so I can ditch the ()'s...</description>
		<content:encoded><![CDATA[<p>That is awesome.  I wondered what would happen in these cases.  I&#8217;m starting to use extension methods more and more to ease common coding tasks.  I&#8217;m glad to see I can refactor my null checks into the extension methods themselves.  Now if we can only get extension properties so I can ditch the ()&#8217;s&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
