<?xml version="1.0" encoding="iso-8859-9"?>
<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>Coskun SUNALI &#124; .net framework, c#, asp.net, atlas, visual studio, iis and everything else &#187; extension methods</title>
	<atom:link href="http://sunali.com/tag/extension-methods/feed/" rel="self" type="application/rss+xml" />
	<link>http://sunali.com</link>
	<description>Coşkun SUNALI</description>
	<lastBuildDate>Fri, 12 Feb 2010 12:35:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Extension methods don&#8217;t compile? No panic!</title>
		<link>http://sunali.com/2008/12/10/extension-methods-dont-compile-no-panic/</link>
		<comments>http://sunali.com/2008/12/10/extension-methods-dont-compile-no-panic/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 15:28:26 +0000</pubDate>
		<dc:creator>Coskun SUNALI</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[extension methods]]></category>

		<guid isPermaLink="false">http://sunali.com/?p=204</guid>
		<description><![CDATA[I came across to a really strange problem today. Some extension methods that I have copied from another project just did not want to be compiled at all. &#8216;string&#8217; does not contain a definition for &#8216;MethodName&#8217;. I have checked everything, including clearing the temporary ASP.NET files within framework folder (C:\Windows\Microsoft.NET\Framework\&#8230;), restarting Visual Studio and even]]></description>
			<content:encoded><![CDATA[<p>I came across to a really strange problem today. Some extension methods that I have copied from another project just did not want to be compiled at all.</p>
<p><em>&#8216;string&#8217; does not contain a definition for &#8216;MethodName&#8217;.</em></p>
<p>I have checked everything, including clearing the temporary ASP.NET files within framework folder (<span style="color: #c0c0c0;">C:\Windows\Microsoft.NET\Framework\&#8230;</span>), restarting Visual Studio and even restarting the OS. The target framework of the projects were all set to 3.5 as well. But unfortunately, nothing helped. Finally, when I compared what kind of configuration I could be missing from web.config, I have found out the missing (and the killer) part.</p>
<p>If you have a similar problem, try adding the following configuration section in your project&#8217;s web.config file.</p>
<pre>  &lt;system.codedom&gt;
    &lt;compilers&gt;
      &lt;compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
        &lt;providerOption name="CompilerVersion" value="v3.5"/&gt;
        &lt;providerOption name="WarnAsError" value="false"/&gt;
      &lt;/compiler&gt;
    &lt;/compilers&gt;
  &lt;/system.codedom&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://sunali.com/2008/12/10/extension-methods-dont-compile-no-panic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Some useful UpdatePanel extensions</title>
		<link>http://sunali.com/2008/12/05/some-useful-updatepanel-extensions/</link>
		<comments>http://sunali.com/2008/12/05/some-useful-updatepanel-extensions/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 16:09:21 +0000</pubDate>
		<dc:creator>Coskun SUNALI</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[extension methods]]></category>

		<guid isPermaLink="false">http://sunali.com/?p=233</guid>
		<description><![CDATA[I want to share some pretty basic and useful UpdatePanel control extensions with you. Method names are self explaining so I will not go deep in details. public static void AlertOnLoad(this UpdatePanel updatePanel, string key, string message) { message = message.Replace("'", "\'").Replace("\r\n", "").Replace("\n", ""); message = "alert('" + message + "');"; AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, message,]]></description>
			<content:encoded><![CDATA[<p>I want to share some pretty basic and useful UpdatePanel control extensions with you. Method names are self explaining so I will not go deep in details.</p>
<pre>public static void AlertOnLoad(this UpdatePanel updatePanel, string key, string message)
{
    message = message.Replace("'", "\'").Replace("\r\n", "").Replace("\n", "");
    message = "alert('" + message + "');";
    AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, message, true);
}

public static void RedirectOnLoad(this UpdatePanel updatePanel, string key, string url)
{
    url = "top.location.href = '" + url + "';";
    AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, url, true);
}

public static void OpenWindowOnLoad(this UpdatePanel updatePanel, string key, string url)
{
    url = "window.open('" + url + "');";
    AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, url, true);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://sunali.com/2008/12/05/some-useful-updatepanel-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strip all HTML tags from string</title>
		<link>http://sunali.com/2008/11/09/strip-all-html-tags-from-string/</link>
		<comments>http://sunali.com/2008/11/09/strip-all-html-tags-from-string/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 09:15:57 +0000</pubDate>
		<dc:creator>Coskun SUNALI</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[extension methods]]></category>

		<guid isPermaLink="false">http://sunali.com/?p=239</guid>
		<description><![CDATA[This is something we need very often. Either for security reasons or just because of some business rules. I will share a small code snippet with you as an extension method to string type so you can take advantages of using Regular Expressions to remove HTML tags from any user input. public static string StripHtml(this]]></description>
			<content:encoded><![CDATA[<p>This is something we need very often. Either for security reasons or just because of some business rules. I will share a small code snippet with you as an extension method to <em>string</em> type so you can take advantages of using Regular Expressions to remove HTML tags from any user input.<br />
<code> </code></p>
<pre>public static string StripHtml(this string value)
{
    if (string.IsNullOrEmpty(value))
    {
        return string.Empty;
    }

    value = Regex.Replace(value, @"&lt;(.|\n)*?&gt;", string.Empty, RegexOptions.Multiline | RegexOptions.IgnoreCase);

    return value;
}</pre>
<p>And this is how you need to use it:</p>
<pre>string var = txUserInput.Text;
var = var.StringHtml();</pre>
]]></content:encoded>
			<wfw:commentRss>http://sunali.com/2008/11/09/strip-all-html-tags-from-string/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to uppercase the first letter of a word or sentence</title>
		<link>http://sunali.com/2008/11/01/how-to-uppercase-the-first-letter-of-a-word-or-sentence/</link>
		<comments>http://sunali.com/2008/11/01/how-to-uppercase-the-first-letter-of-a-word-or-sentence/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 07:41:04 +0000</pubDate>
		<dc:creator>Coskun SUNALI</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[.net framework]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[extension methods]]></category>

		<guid isPermaLink="false">http://sunali.com/?p=245</guid>
		<description><![CDATA[When I used to use PHP to develop my web applications, I really loved its basic but useful method named ucfirst. This function is explained using a simple explanation on PHP documentation: ucfirst &#8212; Make a string&#8217;s first character uppercase I believe within all those useful and complex libraries taking place in .NET Framework, it]]></description>
			<content:encoded><![CDATA[<p>When I used to use PHP to develop my web applications, I really loved its basic but useful method named <a href="www.php.net/manual/en/function.ucfirst.php" target="_blank"><em>ucfirst</em></a>. This function is explained using a simple explanation on PHP documentation:</p>
<p class="refpurpose"><strong><span class="refname">ucfirst</span> &#8212; <span class="dc-title">Make a string&#8217;s first character uppercase</span></strong></p>
<p>I believe within all those useful and complex libraries taking place in .NET Framework, it still misses these kind of basic and useful methods. However, the good side is that we can extend it using our custom extension methods.</p>
<p>Because I needed to implement such a feature as PHP offers using <strong>ucfirst</strong> function, I wrote the following simple extension to achieve the same functionality.</p>
<p><code> </code></p>
<pre>/// &lt;summary&gt;
/// Capitalizes the first letter of the word.
/// &lt;/summary&gt;
/// &lt;param name="value"&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
public static string ToUpperFirst(this string value)
{
    if (string.IsNullOrEmpty(value))
    {
        return string.Empty;
    }

    if (value.Length &gt; 1)
    {
        return
            string.Format("{0}{1}",
                value.Substring(0, 1).ToUpper(),
                value.Substring(1).ToLower()
            );
    }
    else
    {
        return value.ToUpper();
    }
}</pre>
<p>And this is how to use it:</p>
<p><code> </code></p>
<pre>string val = "something";
val = val.ToUpperFirst(); // result = Something</pre>
]]></content:encoded>
			<wfw:commentRss>http://sunali.com/2008/11/01/how-to-uppercase-the-first-letter-of-a-word-or-sentence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
