<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1736693021787496950</id><updated>2024-09-16T19:32:51.518+01:00</updated><category term="C#"/><category term="csharp"/><category term="extension method"/><category term=".NET 2.0"/><category term=".NET 3.5"/><category term="SQL Server"/><category term="SQL Server 2005"/><category term="T-SQL"/><category term="XML"/><category term="class"/><category term="conversion"/><category term="convert"/><category term="mixin"/><category term="string"/><category term="visual studio"/><category term="CDATA"/><category term="CLR"/><category term="ClickOnce"/><category term="LINQ"/><category term="SMO"/><category term="StreamReader"/><category term="System.Delegate"/><category term="WCF"/><category term="WCF Extensions"/><category term="WinForms"/><category term="Windows Forms"/><category term="XSLT"/><category term="XmlDocument"/><category term="batch"/><category term="constructor"/><category term="debug"/><category term="debugger"/><category term="delegate"/><category term="empty"/><category term="equality"/><category term="escaping"/><category term="int"/><category term="namespaces"/><category term="null"/><category term="operator overloading"/><category term="parsing"/><category term="partial class"/><category term="recursion"/><category term="script"/><category term="xsd.exe"/><title type='text'>godevelop</title><subtitle type='html'>Every day&#39;s adventures in .NET Framework</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>17</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-6586378595473331222</id><published>2008-02-21T22:23:00.001+00:00</published><updated>2008-02-22T14:06:39.273+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET 3.5"/><category scheme="http://www.blogger.com/atom/ns#" term="visual studio"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF"/><category scheme="http://www.blogger.com/atom/ns#" term="WCF Extensions"/><title type='text'>Installing WCF/WPF Extensions for VS 2005 after .NET Framework SP1</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;How to install WCF/WPF Extensions for Visual Studio 2005 if you&#39;ve already installed .NET Framework 3.0 SP1?&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;If you have .NET Framework 3.0 SP1 installed on your machine, when attempting to install the Extensions - you&#39;ll get an error message saying:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Setup has detected that a prerequisite is missing.  To use Visual Studio 2005 extensions for .NET Framework 3.0 (WCF &amp; WPF), November 2006 CTP you must have the .NET Framework 3.0 runtime installed.  Please install the .NET Framework 3.0 runtime and restart setup.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Now, apparently .NET Framework 3.0 SP1 is not .NET Framework 3.0 for the Extensions installer.&lt;br /&gt;&lt;br /&gt;Seems like the best way to go around this problem is to fool the Extensions installer by putting a fake key into the registry:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{15095BF3-A3D7-4DDF-B193-3A496881E003}]&lt;br /&gt;&quot;DisplayName&quot;=&quot;Microsoft .NET Framework 3.0&quot;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;Worked for me! :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;see: &lt;a href=&quot;http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2550726&amp;SiteID=1&quot;&gt;Visual Studio 2005 WPF Extensions Problem&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/6586378595473331222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/6586378595473331222' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6586378595473331222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6586378595473331222'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2008/02/installing-wcfwpf-extensions-for-vs.html' title='Installing WCF/WPF Extensions for VS 2005 after .NET Framework SP1'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-7696334264457773437</id><published>2008-02-21T21:56:00.000+00:00</published><updated>2008-02-22T14:04:53.825+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET 2.0"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="conversion"/><category scheme="http://www.blogger.com/atom/ns#" term="convert"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><category scheme="http://www.blogger.com/atom/ns#" term="delegate"/><category scheme="http://www.blogger.com/atom/ns#" term="System.Delegate"/><title type='text'>How to Control.Invoke an Anonymous Method?</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;Why won&#39;t Control.Invoke accept a delegate, even though it&#39;s looking for a Delegate?&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;This might seem like some semantic gymnastics... but when trying to compile this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;this.Invoke(delegate() { MessageBox.Show(&quot;Hello&quot;); });&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;you&#39;ll get:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;Argument &#39;1&#39;: cannot convert from &#39;anonymous method&#39; to &#39;System.Delegate&#39;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;which would suggest that a &lt;strong&gt;delegate&lt;/strong&gt; is not a &lt;strong&gt;Delegate&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;It&#39;s not exactly so - the problem is actually that the compiler does not know to what particular subtype of &lt;strong&gt;System.Delegate&lt;/strong&gt; to cast/convert the anonymous method (delegate) to - and it can&#39;t create an instance of &lt;strong&gt;System.Delegate&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;To make the code work, you have to explicitly create an instance of a particular type of a parameterless delegate returning void, e.g.:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;this.Invoke(new MethodInvoker(delegate() {MessageBox.Show(&quot;Hello&quot;); }));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;see: &lt;a href=&quot;http://weblogs.asp.net/psteele/archive/2007/08/26/anonymous-methods-and-control-invoke.aspx&quot;&gt;Anonymous methods and Control.Invoke&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/7696334264457773437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/7696334264457773437' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/7696334264457773437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/7696334264457773437'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2008/02/how-to-controlinvoke-anonymous-method.html' title='How to Control.Invoke an Anonymous Method?'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-4778302893453407101</id><published>2008-02-13T00:34:00.002+00:00</published><updated>2008-02-21T12:58:56.136+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="debug"/><category scheme="http://www.blogger.com/atom/ns#" term="debugger"/><category scheme="http://www.blogger.com/atom/ns#" term="partial class"/><category scheme="http://www.blogger.com/atom/ns#" term="xsd.exe"/><title type='text'>XSD.exe and DebuggerStepThrough</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;Did you ever try to step into properties of classes generated by XSD.EXE when debugging? It doesn&#39;t work, does it? Not even on methods that you might have extended the XSD.EXE&#39;s partial classes with!&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;It is a common practice to generate partial classes from XSD schemas using XSD.EXE, and then extend some of them in another source file.&lt;br /&gt;&lt;br /&gt;This all works nice and clean, but XSD.EXE is nasty and decorates all the classes it creates with the &lt;strong&gt;DebuggerStepThrough&lt;/strong&gt; attribute.&lt;br /&gt;&lt;br /&gt;That makes the debugger treat not only those parts of the classes that were created by XSD.EXE as &#39;nondebuggable&#39;; you can&#39;t step into you own code (those methods in the class part authored by you), either!&lt;br /&gt;&lt;br /&gt;Now, here are three ways to fix this:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;run a search&amp;replace and get rid of all the &lt;strong&gt;DebuggerStepThrough&lt;/strong&gt; attributes&lt;br /&gt;&lt;li&gt;in Visual Studio, go to &lt;strong&gt;Tools/Options...&lt;/strong&gt;, unfold the tree on the left-hand side of the dialog that will appear down to &lt;strong&gt;Debugging/General&lt;/strong&gt;, and then uncheck the box next to &lt;strong&gt;&#39;Enable Just My Code&#39;&lt;/strong&gt;&lt;br /&gt;(Note that you will still have to set a breakpoint in the code marked as DebuggerStepThrough, otherwise the debugger will skip over it anyway)&lt;br /&gt;&lt;li&gt;stop using XSD.EXE :) (thanks to Marcin for this acute observation)&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Well - the choice is yours :)&lt;br /&gt;&lt;br /&gt;[see: &lt;a href=&quot;http://www.msdner.net/dev-archive/160/12-38-1609231.shtm&quot;&gt;Disable DebuggerStepThroughAttribute in code generated by xsd.exe?&lt;/a&gt;]&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/4778302893453407101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/4778302893453407101' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/4778302893453407101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/4778302893453407101'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2008/02/xsdexe-and-debuggerstepthrough.html' title='XSD.exe and DebuggerStepThrough'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-6508365850286710281</id><published>2008-02-12T23:45:00.000+00:00</published><updated>2008-02-13T16:41:17.426+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="conversion"/><category scheme="http://www.blogger.com/atom/ns#" term="convert"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><category scheme="http://www.blogger.com/atom/ns#" term="int"/><category scheme="http://www.blogger.com/atom/ns#" term="string"/><title type='text'>Convert an Array of Integers to an Array of Strings</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;This is just brilliant!&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;int[] ints = new int[] { 1, 2, 3, 4 };&lt;br /&gt;string[] strings = Array.ConvertAll&lt;int, string&gt;(ints, Convert.ToString);&lt;/pre&gt;see: &lt;a href=&quot;http://www.irishdev.com/blogs/kieranlynam/archive/2007/09/26/4334.aspx&quot;&gt;Kieran Lynam&#39;s Blog&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/6508365850286710281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/6508365850286710281' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6508365850286710281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6508365850286710281'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2008/02/convert-array-of-integers-to-array-of.html' title='Convert an Array of Integers to an Array of Strings'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-4786137217783805283</id><published>2008-02-12T23:29:00.002+00:00</published><updated>2008-02-13T16:37:11.702+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET 2.0"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><category scheme="http://www.blogger.com/atom/ns#" term="empty"/><category scheme="http://www.blogger.com/atom/ns#" term="null"/><category scheme="http://www.blogger.com/atom/ns#" term="string"/><title type='text'>Check a String for Null or Empty</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;Yes, the method that .NET Framework 2.0 provides is the fastest.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;You used to do it this way (I hope :):&lt;br /&gt;&lt;pre&gt;if (s == null || s.Length == 0)&lt;/pre&gt;&lt;br /&gt;Checking the length is faster that comparing to &quot;&quot; or string.Empty, because the length is simply stored together with the string&#39;s content on the heap (see: &lt;a href=&quot;http://www.yoda.arachsys.com/csharp/strings.html&quot;&gt;Strings in .NET and C#&lt;/a&gt;, &#39;Memory usage&#39;).&lt;br /&gt;&lt;br /&gt;.NET Framework 2.0 put the above check into a single static method of string:&lt;br /&gt;&lt;pre&gt;if (string.IsNullOrEmpty(s))&lt;/pre&gt;&lt;br /&gt;For all the doubting Thomases ;) - this guy actually tested it:&lt;br /&gt;&lt;a href=&quot;http://jstawski.com/archive/2006/12/08/String.Empty_2C00_-null_2C00_-Length_2C00_-or-String.IsEmptyOrNull-_3F00_.aspx&quot;&gt;String.Empty, null, Length, or String.IsEmptyOrNull&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/4786137217783805283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/4786137217783805283' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/4786137217783805283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/4786137217783805283'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2008/02/check-string-for-null-or-empty.html' title='Check a String for Null or Empty'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-542265963099216966</id><published>2008-02-05T21:20:00.005+00:00</published><updated>2008-02-21T13:02:52.742+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CDATA"/><category scheme="http://www.blogger.com/atom/ns#" term="escaping"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><category scheme="http://www.blogger.com/atom/ns#" term="XSLT"/><title type='text'>]]&gt; Inside CDATA Section</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;Ever needed to put ]]&amp;gt; inside a CDATA section? Here&#39;s how.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Seems like there are two ways actually:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;escape the &#39;&amp;gt;&#39; character as &amp;amp;gt;&lt;br /&gt;&lt;li&gt;split the CDATA section into two sections:&lt;pre&gt;&lt;someTag&gt;&amp;lt;![CDATA[A CDATA text with a ]]]]&amp;gt;&amp;lt;![CDATA[&gt; in it]]&gt;&lt;br /&gt;&lt;/someTag&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/ul&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br /&gt;Cool! (It demanded a little more escaping from me to make the above look as it looks ;) )&lt;br /&gt;&lt;br /&gt;Based on: &lt;a href=&quot;http://www.thescripts.com/forum/thread85152.html&quot;&gt;How can I have &#39;]]&gt;&#39; as a text inside CDATA in xml&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/542265963099216966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/542265963099216966' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/542265963099216966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/542265963099216966'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2008/02/inside-cdata-section.html' title=']]&gt; Inside CDATA Section'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-3966370565299965830</id><published>2008-01-18T19:30:00.000+00:00</published><updated>2008-02-08T14:57:07.135+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET 3.5"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><category scheme="http://www.blogger.com/atom/ns#" term="extension method"/><title type='text'>Calling Methods on a Null Reference???</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;Is it really possible to call a method of a reference pointing to null?&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Take a look at this piece of code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;static void Main ( )&lt;br /&gt;{&lt;br /&gt;   MySecondType myObject = null;&lt;br /&gt;   myObject = myObject.Parse(&quot;10&quot;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Is it possible to make it actually run and not generate a &#39;null reference&#39; exception?&lt;br /&gt;&lt;br /&gt;Well, as long as you&#39;re using .NET 3.5 - it is! :)&lt;br /&gt;&lt;br /&gt;The idea is to declare the &lt;b&gt;Parse&lt;/b&gt; method as an extension method operating on objects of type MySecondType:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;static class MySecondTypeExtensions&lt;br /&gt;{&lt;br /&gt;  public static MySecondType Parse ( this MySecondType me, string text )&lt;br /&gt;  {&lt;br /&gt;    Int32 value = Int32.Parse(text);&lt;br /&gt;    return new MySecondType(value);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  //...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As you can see - it does not matter if &lt;b&gt;me&lt;/b&gt; points to null - since the method operates on the &lt;b&gt;text&lt;/b&gt; parameter only!&lt;br /&gt;&lt;br /&gt;So - nothing makes it illegal to call it on &lt;b&gt;myObject&lt;/b&gt; - even though &lt;b&gt;myObject&lt;/b&gt; point to null :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The broader context is here:&lt;br /&gt;&lt;a href=&quot;http://msdn2.microsoft.com/en-ie/vcsharp/bb978522(en-us).aspx&quot;&gt;Inferred Typing with Factory Methods as Extension Methods&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/3966370565299965830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/3966370565299965830' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/3966370565299965830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/3966370565299965830'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2008/01/calling-methods-on-null-reference.html' title='Calling Methods on a Null Reference???'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-1943490069364369100</id><published>2007-11-07T16:47:00.000+00:00</published><updated>2007-11-07T16:58:27.971+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ClickOnce"/><category scheme="http://www.blogger.com/atom/ns#" term="CLR"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><category scheme="http://www.blogger.com/atom/ns#" term="visual studio"/><title type='text'>Could not find file &#39;Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0&#39;</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;When the compiler cannot find the Common Language Runtime, you can become confused...&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I recently made some uncontrolled move with my mouse while holding down its left button over the Solution Explorer in Visual Studio - it sometimes just happens, you know... (too much coffee???)&lt;br /&gt;&lt;br /&gt;Anyway - I knew something happened, because noticed that the window blinked and looked like digesting something for a second or two... I tried to find some file moved into some strange folder or something, but could find anything like that - so I just continued to write code.&lt;br /&gt;&lt;br /&gt;And then - after a few minutes, when I hit Ctrl+Shift+B - I got this error:&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;Could not find file &#39;Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0&#39;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;Excuse me? Come again (I hit Ctrl+Shift+B once more)?!?&lt;br /&gt;&lt;br /&gt;Yeah, apparently the CLR had been uninstalled - oh, no problem, happens every other day, right?&lt;br /&gt;&lt;br /&gt;Seriously - the error did not want to go away, and (of course) it was the worst moment for something like that to appear, so I started googling... and found out, that it actually does happen - well, not the uninstallation of the CLR, but the error message.&lt;br /&gt;&lt;br /&gt;The cause of the error message is this: &lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;If I activate the &quot;Enable ClickOnce Security Settings&quot; [in Project Properties] I get the error, if I disable this feature it compiles correctly.&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;[&lt;a href=&quot;http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=148745&amp;SiteID=1&quot;&gt;http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=148745&amp;SiteID=1&lt;/a&gt;]&lt;br /&gt;&lt;br /&gt;Perfectly reasonable, eh?&lt;br /&gt;&lt;br /&gt;Anyway - the real question is now - what kind of crazy jerk must I have done with my mouse to turn that option on???</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/1943490069364369100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/1943490069364369100' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/1943490069364369100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/1943490069364369100'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/11/could-not-find-file-microsoftwindowscom.html' title='Could not find file &#39;Microsoft.Windows.CommonLanguageRuntime, Version=2.0.50727.0&#39;'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-5058079599050476221</id><published>2007-10-17T12:35:00.000+01:00</published><updated>2007-10-17T12:35:44.815+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><category scheme="http://www.blogger.com/atom/ns#" term="extension method"/><category scheme="http://www.blogger.com/atom/ns#" term="LINQ"/><category scheme="http://www.blogger.com/atom/ns#" term="mixin"/><title type='text'>LINQ - extension methods in action</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;As promised in one of previous &lt;a href=&quot;http://godevelop.blogspot.com/2007/10/extension-methods-in-c-30.html&quot;&gt;posts&lt;/a&gt; - more about extension methods. Let&#39;s have a look at... LINQ!&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;You remember extension methods, whose simplest definition would be:&lt;br /&gt;&lt;blockquote&gt;Extension methods are basically static methods that are callable through an instance syntax&lt;/blockquote&gt;[&lt;a href=&quot;http://msdn.microsoft.com/msdnmag/issues/07/06/CSharp30/&quot;&gt;The Evolution Of LINQ And Its Impact On The Design Of C#&lt;/a&gt;]&lt;br /&gt;&lt;br /&gt;It seems like they were introduced in C# 3.0 to make LINQ work fully.&lt;br /&gt;&lt;br /&gt;LINQ is a language feature allowing to query collections in a SQL-like manner (SELECT statement), something like:&lt;br /&gt;&lt;pre&gt;var locals = from c in customers&lt;br /&gt;             where c.ZipCode == 91822&lt;br /&gt;             select new { FullName = c.FirstName + “ “ +&lt;br /&gt;                          c.LastName, HomeAddress = c.Address };&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So - where are extension methods here?&lt;br /&gt;&lt;br /&gt;Well - the sample above is actually syntactic sugar, being equivalent to:&lt;br /&gt;&lt;pre&gt;var locals =&lt;br /&gt;   customers&lt;br /&gt;       .Where(c =&gt; c.ZipCode == 91822)&lt;br /&gt;       .Select(c =&gt; new { FullName = c.FirstName + “ “ + c.LastName, &lt;br /&gt;                          HomeAddress = c.Address });&lt;/pre&gt;&lt;br /&gt;Now, let&#39;s assume &lt;strong&gt;customers&lt;/strong&gt; are of type IEnumerable&amp;lt;Customer&amp;gt;. &lt;strong&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/strong&gt; has only one method: &lt;strong&gt;GetEnumerator&amp;lt;T&amp;gt;&lt;/strong&gt;. This means that both &lt;strong&gt;Where&lt;/strong&gt; and &lt;strong&gt;Select&lt;/strong&gt; must be extension methods, which mix the SQL-like functionalities into all &lt;strong&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/strong&gt;-s!&lt;br /&gt;&lt;br /&gt;In fact the &lt;strong&gt;Where&lt;/strong&gt; method is very simple:&lt;br /&gt;&lt;pre&gt;class EnumerableExtensions&lt;br /&gt;{&lt;br /&gt;    public delegate T Func&lt;A0, T&gt;(A0 arg0);&lt;br /&gt;&lt;br /&gt;    public static IEnumerable&lt;T&gt; Where&lt;T&gt;(this IEnumerable&lt;T&gt; source, Func&lt;T, bool&gt; predicate)&lt;br /&gt;    {&lt;br /&gt;        foreach (T element in source)&lt;br /&gt;        {&lt;br /&gt;            if (predicate(element)) yield return element;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;It takes the &lt;strong&gt;IEnumerable&amp;lt;T&amp;gt; source&lt;/strong&gt; parameter - which is preceded by the &lt;strong&gt;this&lt;/strong&gt; keyword (so it&#39;s going to extend the &lt;strong&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/strong&gt; type), and the &lt;strong&gt;predicate&lt;/strong&gt; delegate.&lt;br /&gt;It can then use the &lt;strong&gt;predicate&lt;/strong&gt; to tell whether each &lt;strong&gt;element&lt;/strong&gt; in the &lt;strong&gt;source&lt;/strong&gt; satisfies the &quot;WHERE clause&quot;.&lt;br /&gt;Those, that do - are put into the resulting collection of the &lt;strong&gt;Where&lt;/strong&gt; method (using the &lt;strong&gt;yield&lt;/strong&gt; keyword).&lt;br /&gt;&lt;br /&gt;So, basically the following:&lt;br /&gt;&lt;pre&gt;customers.Where(c =&gt; c.ZipCode == 91822)&lt;/pre&gt;&lt;br /&gt;will result in calling the static &lt;strong&gt;Where&lt;/strong&gt; method against the &lt;strong&gt;customers&lt;/strong&gt; object, with the &lt;strong&gt;Func&amp;lt;T, bool&amp;gt; predicate&lt;/strong&gt; set to this anonymous method:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;delegate {&lt;br /&gt;    if (c.ZipCode == 91822) yield return c;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Yep, that&#39;s what happened to the:&lt;pre&gt;c =&gt; c.ZipCode == 91822&lt;/pre&gt;thing, which is actually a &lt;a href=&quot;http://www.developer.com/net/csharp/article.php/3598381&quot;&gt;lambda expression&lt;/a&gt; - another syntactic sugar in C# 3.0, on which more some other time.</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/5058079599050476221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/5058079599050476221' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/5058079599050476221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/5058079599050476221'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/10/linq-extension-methods-in-action.html' title='LINQ - extension methods in action'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-1375768671486462062</id><published>2007-10-07T19:45:00.000+01:00</published><updated>2007-10-08T20:41:27.718+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="constructor"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><title type='text'>Interview Questions: Constructors in C#</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;A good interview-type question: constructors in C#.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Here&#39;s a good one for an interview (whether you&#39;re the interviewer or the interviewee):&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;When declaring a constructor in the subclass, should I explicitly call the base class&#39;s constructor?&lt;br /&gt;And if I don&#39;t - will the base class&#39;s constructor get called anyway?&lt;/blockquote&gt;&lt;br /&gt;That&#39;s basically what a discussion between my friend Marcin and me got down to...&lt;br /&gt;&lt;br /&gt;If you&#39;ve ever used &lt;a href=&quot;http://www.jetbrains.com/resharper/&quot;&gt;Resharper&lt;/a&gt; (don&#39;t tell me you haven&#39;t!), you might have noticed that when you go:&lt;br /&gt;&lt;pre&gt;class SubClass : BaseClass&lt;br /&gt;{&lt;br /&gt;   public SubClass() : base()&lt;br /&gt;   {&lt;br /&gt;      // some code here&lt;br /&gt;   } &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;it will gray out &lt;strong&gt;base()&lt;/strong&gt;, because it is redundant.&lt;br /&gt;&lt;br /&gt;And it&#39;s true - because if the base constructor wasn&#39;t called, the object might not get fully initialized - and that would in a sense break the &lt;a href=&quot;http://en.wikipedia.org/wiki/Liskov_substitution_principle&quot;&gt;Liskov&#39;s Substitution Principle&lt;/a&gt;...&lt;br /&gt;&lt;br /&gt;Actually - you do not have to &quot;agree&quot; for the base parameterless constructor to be invoked. You can choose a different one instead:&lt;br /&gt;&lt;pre&gt;public SubClass() : base(5)&lt;br /&gt;{&lt;br /&gt;   // some code here&lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;However - if you look at this summary &lt;a href=&quot;http://www.yoda.arachsys.com/csharp/constructors.html&quot;&gt;C# Constructors&lt;/a&gt;:&lt;br /&gt;&lt;blockquote&gt;There must always be a &quot;chain&quot; of constructors which runs constructors all the way up the class hierarchy. Every class in the hierarchy will have a constructor invoked, although some of those constructors may not explicitly appear in the code.&lt;/blockquote&gt;&lt;br /&gt;All clear now, eh? ;)</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/1375768671486462062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/1375768671486462062' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/1375768671486462062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/1375768671486462062'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/10/interview-questions-constructors-in-c.html' title='Interview Questions: Constructors in C#'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-8382963466092959231</id><published>2007-10-01T21:07:00.001+01:00</published><updated>2007-10-02T13:34:31.134+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="csharp"/><category scheme="http://www.blogger.com/atom/ns#" term="extension method"/><category scheme="http://www.blogger.com/atom/ns#" term="mixin"/><title type='text'>Extension Methods in C# 3.0</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;This is actually &quot;old stuff&quot; today - but it is really cool: extension methods in C# 3.0 and mixins!&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Ever wanted to raise a double to the power of another double without having to go like:&lt;br /&gt;&lt;pre&gt;Math.Pow(10.343, 302.34);&lt;/pre&gt;?&lt;br /&gt;&lt;br /&gt;Well, what do you say for that:&lt;br /&gt;&lt;pre&gt;(10.343).RaiseToPower(302.34);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That would be very nice, and... it is possible, as long as:&lt;br /&gt;&lt;br /&gt;&lt;li&gt;you are using C# 3.0&lt;/li&gt;&lt;br /&gt;&lt;li&gt;you have implemented an &lt;strong&gt;extension method &lt;/strong&gt;like this:&lt;/li&gt;&lt;br /&gt;&lt;pre&gt;    public static class Powerade&lt;br /&gt;    {&lt;br /&gt;        public static double RaiseToPower(this double x, double y)&lt;br /&gt;        {&lt;br /&gt;            return Math.Pow(x, y);&lt;br /&gt;        }&lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;This is of course a quite useless example, but what extension methods are in essence is a way to implement &lt;a href=&quot;http://en.wikipedia.org/wiki/Mixin&quot;&gt;mixins&lt;/a&gt; in C# 3.0: you can &quot;mix in&quot; some functionality to a type that is already there.&lt;br /&gt;&lt;br /&gt;More on mixins soon.</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/8382963466092959231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/8382963466092959231' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/8382963466092959231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/8382963466092959231'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/10/extension-methods-in-c-30.html' title='Extension Methods in C# 3.0'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-9002684040467411807</id><published>2007-09-24T21:10:00.000+01:00</published><updated>2007-09-26T17:31:33.552+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><title type='text'>MERGE Statement in SQL Server</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;Ever had to merge two tables in SQL? Hard work?&lt;br /&gt;The MERGE statement is only available in SQL Server 2008 (and Oracle and DB2 ;) ), but in the meantime - you can mimic it.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;If you ever had a large csv file with a new version of data already contained in a table in SQL, you dreamed of something like this, didn&#39;t you:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;MERGE t1&lt;br /&gt;USING (SELECT @id AS id, @name1 AS name1) AS t2 ON t1.id = t2.id&lt;br /&gt;WHEN MATCHED&lt;br /&gt;    THEN UPDATE SET t1.name1 = t2.name1&lt;br /&gt;WHEN NOT MATCHED&lt;br /&gt;    THEN INSERT VALUES(@id, @name1)&lt;/pre&gt;In other words: if the id of a row in the new version matches one in the old version - update the old row; otherwise - insert a new row.&lt;br /&gt;&lt;br /&gt;[Of course we&#39;re assuming here that you managed to load the contents of the csv file into a staging table].&lt;br /&gt;&lt;br /&gt;Well, if you have the luxury of working with SQL Server 2008, the construct above is exactly what you could use there. Have a look here: &lt;a href=&quot;http://blogs.techrepublic.com.com/datacenter/?p=194&quot;&gt;Using MERGE statement&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now, since SQL Server 2008 is not yet used in too many commercial projects ;) - it is often the case that you have to implement such functionality on your own.&lt;br /&gt;&lt;br /&gt;According to &lt;a href=&quot;http://sqlserver-tips.blogspot.com/&quot;&gt;Alex Kuznetsov (MVP)&lt;/a&gt;:&lt;br /&gt;&lt;blockquote&gt;In SQL Server 2005 you can use OUTPUT clause of an UPDATE statement&lt;/blockquote&gt; in order to achieve that.&lt;br /&gt;&lt;br /&gt;See for yourself:&lt;br /&gt;&lt;pre&gt;declare @updated_ids table(id int)&lt;br /&gt;&lt;br /&gt;update permanent set d=s.d, comment = &#39;Modified Row&#39;&lt;br /&gt;output inserted.id into @updated_ids&lt;br /&gt;from permanent p, staging s&lt;br /&gt;where p.id=s.id&lt;br /&gt;&lt;br /&gt;insert into permanent&lt;br /&gt;select id, d, &#39;New Row&#39; from staging where id not in(select id from @updated_ids)&lt;br /&gt;go&lt;/pre&gt;Pretty neat!&lt;br /&gt;&lt;br /&gt;You can find Alex&#39;s whole post here: &lt;a href=&quot;http://sqlserver-tips.blogspot.com/2006/09/mimicking-merge-statement-in-sql.html&quot;&gt;Mimicking MERGE Statement in SQL 2005&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/9002684040467411807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/9002684040467411807' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/9002684040467411807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/9002684040467411807'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/09/merge-statement-in-sql-server.html' title='MERGE Statement in SQL Server'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-6185307608417776043</id><published>2007-09-18T20:21:00.000+01:00</published><updated>2008-02-08T14:55:19.242+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="namespaces"/><category scheme="http://www.blogger.com/atom/ns#" term="parsing"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><category scheme="http://www.blogger.com/atom/ns#" term="XmlDocument"/><title type='text'>Parsing Xml with a Default Namespace Defined</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;What&#39;s that namespace doing there?&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I recently answered a question on MS newsgroups regarding navigating an XML document whose fragment is below:&lt;br /&gt;&lt;pre&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;br /&gt;&amp;lt;JMF xmlns=&quot;http://www.CIP4.org/JDFSchema_1_1&quot; Version=&quot;1.2&quot;&lt;br /&gt;xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&amp;gt;&lt;br /&gt;  &amp;lt;Response ID=&quot;RDFS1934507113653e9&quot; ReturnCode=&quot;0&quot; Type=&quot;QueueStatus&quot;&lt;br /&gt;refID=&quot;132413dj323s223&quot; xsi:type=&quot;ResponseQueueStatus&quot;&amp;gt;&lt;br /&gt;    &amp;lt;Queue DeviceID=&quot;Dev01&quot; QueueSize=&quot;8&quot; Status=&quot;Waiting&quot;&amp;gt;&lt;br /&gt;      &amp;lt;QueueEntry DeviceID=&quot;vl-5001&quot; JobID=&quot;1048655&quot; JobPartID=&quot;79&quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The author of the question wanted to get to the QueueEntry using the following XPath expression:&lt;br /&gt;&lt;pre&gt;JMF/Response/Queue/QueueEntry&lt;/pre&gt;Unfortunately - it returned no XmlNodes (when used in xmlDoc.SelectNodes(...)).&lt;br /&gt;&lt;br /&gt;And here&#39;s why: &lt;br /&gt;&lt;pre&gt;&amp;lt;JMF xmlns=&quot;http://www.CIP4.org/JDFSchema_1_1&quot; ...&lt;/pre&gt;This means that all children of the &amp;lt;JMF&amp;gt; are in the &quot;http://www.CIP4.org/JDFSchema_1_1&quot; namespace.&lt;br /&gt;So if you try to reference them without specifying that namespace, you are actually trying to reference some nodes that do not exist in the document!&lt;br /&gt;&lt;br /&gt;Here&#39;s what you have to do to be able to select those nodes:&lt;br /&gt;&lt;pre&gt;XmlDocument xmlDoc = new XmlDocument(); &lt;br /&gt;xmlDoc.LoadXml(doc); &lt;br /&gt;&lt;br /&gt;XmlNamespaceManager nm = new &lt;br /&gt;XmlNamespaceManager(xmlDoc.NameTable); &lt;br /&gt;nm.AddNamespace(&quot;my&quot;, &quot;http://www.CIP4.org/JDFSchema_1_1&quot;); &lt;br /&gt;&lt;br /&gt;XmlNodeList list = &lt;br /&gt;xmlDoc.SelectNodes(&quot;/my:JMF/my:Response/my:Queue/my:QueueEntry&quot;, nm); &lt;br /&gt;foreach (XmlNode node in list) &lt;br /&gt;{ &lt;br /&gt;  string sID = node.Attributes[&quot;DeviceID&quot;].Value; &lt;br /&gt;}&lt;/pre&gt;Yeah, it looks a little bit cumbersome, but it works! :)</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/6185307608417776043/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/6185307608417776043' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6185307608417776043'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6185307608417776043'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/09/parsing-xml-with-default-namespace.html' title='Parsing Xml with a Default Namespace Defined'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-3437043792997361631</id><published>2007-09-17T12:23:00.000+01:00</published><updated>2007-09-19T13:38:10.825+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="batch"/><category scheme="http://www.blogger.com/atom/ns#" term="script"/><category scheme="http://www.blogger.com/atom/ns#" term="SMO"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2005"/><category scheme="http://www.blogger.com/atom/ns#" term="T-SQL"/><title type='text'>How to Execute a SQL Script from .NET Code?</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;The old days of splitting scripts by the GO statement or using osql are over! SMO is here!&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;It happens from time to time that you need to execute a T-SQL script - e.g. you are writing a database update manager or whatever.&lt;br /&gt;&lt;br /&gt;And it&#39;s always the old problem of the &#39;GO&#39; separator, isn&#39;t it? ADO.NET just won&#39;t swallow it!&lt;br /&gt;&lt;br /&gt;The solution was always to either use some external tool (like osql or sqlcmd) to execute the script or to parse the script for all the &#39;GO&#39;-es. But both those methods were kind of... not perfect.&lt;br /&gt;&lt;br /&gt;The good news is - you don&#39;t have to worry about it anymore!&lt;br /&gt;&lt;br /&gt;If you have a closer look at &lt;strong&gt;SQL Server Management Objects&lt;/strong&gt; (SMO), you will find the following method:&lt;br /&gt;&lt;pre&gt;Server.ConnectionContext.ExecuteNonQuery()&lt;/pre&gt;which can actually do all the job for you!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If course it is only available in SQL Server 2005. But isn&#39;t that what progress is all about - new things have more features than old ones? ;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can find the SMO assemblies here:&lt;br /&gt;&lt;pre&gt;C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies&lt;/pre&gt;if you have SQL Server 2005 installed on your machine.</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/3437043792997361631/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/3437043792997361631' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/3437043792997361631'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/3437043792997361631'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/09/how-to-execute-sql-script-from-net-code.html' title='How to Execute a SQL Script from .NET Code?'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-7198296183721500234</id><published>2007-09-14T21:43:00.000+01:00</published><updated>2007-09-18T17:04:58.971+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="equality"/><category scheme="http://www.blogger.com/atom/ns#" term="operator overloading"/><category scheme="http://www.blogger.com/atom/ns#" term="recursion"/><title type='text'>overloading operator==</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;Beware of infinite recursion when overloading the == operator!&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;When you overload the equality operator (==) in C#, you should of course remember that:&lt;br /&gt;&lt;br /&gt;&lt;li&gt;you should also overload operator !=&lt;/li&gt;&lt;br /&gt;&lt;li&gt;the operator&#39;s implementation should not throw exceptions&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;Having to overload the unequality operator (!=) as well is rather obvious. Saying:&lt;br /&gt;&lt;pre&gt;a != b&lt;/pre&gt;is another way of saying:&lt;pre&gt;!(a == b)&lt;/pre&gt;&lt;br /&gt;The second point is not unusual, either. No one would rather expect an operator to throw an exception - otherwise, you&#39;d have to put every other if statement in a try-catch block.&lt;br /&gt;&lt;br /&gt;And what would you actually do with a &quot;CouldNotCheckForEqualityException&quot; anyway? It&#39;s not a kind of error you&#39;d expect at runtime, is it? If you can&#39;t check two objects for equality - you would rather like to know that at compile time!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now - in order to protect yourself from throwing an exception in the implementation of the == operator, you should check its arguments for being null, so that you can safely access their fields for comparison purposes.&lt;br /&gt;&lt;br /&gt;Oh, that&#39;s simple, isn&#39;t it?&lt;br /&gt;&lt;pre&gt;if (x == null)&lt;br /&gt;    return y == null;&lt;br /&gt;else&lt;br /&gt;    return x.Equals(y);&lt;/pre&gt;&lt;br /&gt;Pretty clever, eh? But this will NOT work, unfortunately!&lt;br /&gt;Note that the two comparisons to null will actually call the &lt;strong&gt;overloaded&lt;/strong&gt; == operator, causing an &lt;strong&gt;infinite recursion&lt;/strong&gt;!&lt;br /&gt;&lt;br /&gt;There are actually two ways of fixing that:&lt;br /&gt;&lt;br /&gt;&lt;li&gt;you could call x.ReferenceEquals(null) - not too elegant for me, or&lt;br /&gt;&lt;li&gt;you could cast the arguments to objects:&lt;br /&gt;&lt;pre&gt;if ((object) x == null)&lt;br /&gt;    return (object) y == null;&lt;br /&gt;else&lt;br /&gt;    return x.Equals(y);&lt;/pre&gt;&lt;br /&gt;And that&#39;s what I call a really clever and slick piece of code :)&lt;br /&gt;Thanks go to the author of this post for sharing it:&lt;br /&gt;&lt;a href=&quot;http://www.thescripts.com/forum/post923936-3.html&quot;&gt;Re: Overloading operator== and comparing to null&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;Oh, and of course the implementation of the != operator would be:&lt;br /&gt;&lt;pre&gt;return !(x == y)&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/7198296183721500234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/7198296183721500234' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/7198296183721500234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/7198296183721500234'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/09/overloading-operator.html' title='overloading operator=='/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-6460093689502877075</id><published>2007-09-12T20:48:00.000+01:00</published><updated>2007-09-18T17:04:05.364+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="StreamReader"/><title type='text'>Access Denied on a Directory</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;I don&#39;t know why that is, but when trying to access a directory instead of a file with a StreamReader (or anything else that uses it), you will get an Access Denied error...&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Try to run the following code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;StreamReader sr = new StreamReader(@&quot;c:\&quot;);&lt;/pre&gt;Actually - before you run it - try to guess what error it might generate...&lt;br /&gt;Ok - now, make a note of your answer, and run to code.&lt;br /&gt;&lt;br /&gt;Well? Was your guess right?&lt;br /&gt;&lt;br /&gt;I know, I know - it doesn&#39;t seem to make much sense, but the actual error message is:&lt;br /&gt;&lt;blockquote&gt;Access Denied&lt;/blockquote&gt;Apparently, you are not allowed to read from a directory. But the error message is at least misleading. It mislead me for some time when I started looking for the cause of this error.&lt;br /&gt;&lt;br /&gt;Of course the code I was debugging was not that simple as the one above - and that&#39;s why it took me quite a long time to notice, that I&#39;m pointing to a directory, while wanting to load a file into an XmlDocument.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Anyway - access denied does not always stem from insufficient user rights ;)</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/6460093689502877075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/6460093689502877075' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6460093689502877075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/6460093689502877075'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/09/access-denied-on-directory.html' title='Access Denied on a Directory'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1736693021787496950.post-2131460485400733065</id><published>2007-09-10T21:53:00.000+01:00</published><updated>2007-09-18T17:03:43.126+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="WinForms"/><title type='text'>DialogResult - Remember to Keep It None</title><content type='html'>&lt;div class=&quot;lead&quot;&gt;&lt;br /&gt;If you don&#39;t want to look for the place in code where your modal dialog gets unexpectedly closed before you want it to - remember to set all buttons&#39; DialogResult property to None!&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Everyone applies the &#39;copy-paste&#39; rule from time to time - especially when creating Windows forms. You need another button of the same size - you just copy it and paste it, don&#39;t you?&lt;br /&gt;&lt;br /&gt;Well - you have to watch out! As you might expect - most of the values of the new button&#39;s properties are the same as those of the old one.&lt;br /&gt;That&#39;s good as long as you don&#39;t copy an OK button and use it as an ordinary button.&lt;br /&gt;&lt;br /&gt;An OK button has its DialogResult property set to &quot;OK&quot; (oh, really?).&lt;br /&gt;Now, according to &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.windows.forms.button.dialogresult.aspx&quot;&gt;http://msdn2.microsoft.com/en-us/library/system.windows.forms.button.dialogresult.aspx&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;If the DialogResult for this property is set to anything other than None, and if the parent form was displayed through the ShowDialog method, clicking the button closes the parent form without your having to hook up any events. The form&#39;s DialogResult property is then set to the DialogResult of the button when the button is clicked.&lt;/blockquote&gt;&lt;br /&gt;So - if you copied the OK button and pasted it as some other button, say, &quot;Refresh&quot;, that&#39;s fine.&lt;br /&gt;Then you write some code handling that button&#39;s Click event, e.g. you want it to reload contents of some list on the form.&lt;br /&gt;Now look what happens when you actually click the &quot;Refresh&quot; button: the Click event handler does get executed (the list gets refreshed), but right after that the form is closed!&lt;br /&gt;&lt;br /&gt;If you were debugging the Click event handler, you finally go out of that method&#39;s scope and all of a sudden - you find yourself on the form.ShowDialog() statement.&lt;br /&gt;&lt;br /&gt;It tooks me some time to finally find out what was going on! :)</content><link rel='replies' type='application/atom+xml' href='http://godevelop.blogspot.com/feeds/2131460485400733065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1736693021787496950/2131460485400733065' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/2131460485400733065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1736693021787496950/posts/default/2131460485400733065'/><link rel='alternate' type='text/html' href='http://godevelop.blogspot.com/2007/09/dialogresult-remember-to-keep-it-none.html' title='DialogResult - Remember to Keep It None'/><author><name>Adam Bieganski</name><uri>http://www.blogger.com/profile/07457041641874766456</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>