<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5949924287482705652</atom:id><lastBuildDate>Thu, 02 Feb 2012 14:06:09 +0000</lastBuildDate><category>SQL Server Errors</category><category>Visual Studio</category><category>CLR</category><category>Performance</category><category>Architecture</category><category>SQL</category><category>.NET Framework 4.0</category><category>SQL Injection</category><category>AJAX</category><category>VB.NET</category><category>JScript.NET</category><category>Interview Questions</category><category>XAML</category><category>ASP.NET</category><category>C#.NET and VB.NET Interview Questions</category><category>JQuery</category><category>sqlserver</category><category>silverlight Interview Questions</category><category>Framework</category><category>New Technologies</category><category>Windows Azure</category><category>Error</category><category>Master Pages</category><category>TextBox</category><category>.NET Framework 4.5</category><category>JScript</category><category>Design Patterns</category><category>Cloud</category><category>Threading</category><category>LINQ</category><category>CSS</category><category>silverlight</category><category>GridView</category><category>MVC2</category><category>MVP</category><category>XML</category><category>Triggers</category><category>Session</category><category>IIS</category><category>Web Service</category><category>C#.NET</category><category>SQL Interview Questions</category><category>Crystal Report</category><category>Design Principals</category><category>MVC3</category><category>Browser</category><category>WCF</category><category>ASP.NET Interview Questions</category><category>CHM</category><category>Generic</category><category>OOPs Interview Questions</category><category>datetime</category><category>java script</category><title>DOT NET ACADEMY</title><description>Dot Net Interview Questions and Tutorial

By Rajesh Rolen</description><link>http://dotnetacademy.blogspot.com/</link><managingEditor>noreply@blogger.com (Rajesh Rolen)</managingEditor><generator>Blogger</generator><openSearch:totalResults>439</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/blogspot/FJUvB" /><feedburner:info uri="blogspot/fjuvb" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-1531849529301631291</guid><pubDate>Mon, 30 Jan 2012 19:03:00 +0000</pubDate><atom:updated>2012-01-30T11:05:17.881-08:00</atom:updated><title>Best Extension Methods</title><description>&lt;h3&gt;Below is list of Best Extension Methods of .NET&lt;/h3&gt;



&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-paging-on.html"&gt;Paging on IQueryable&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-paging-on_30.html"&gt;Paging on IEnumerable&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-convert.html"&gt;IEnumerable To DataTable&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-convert-generic.html"&gt;Convert Generic List to DataTable&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-isnullable.html"&gt;Check Is Nullable&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-get-core-type.html"&gt;Get Core Type&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-is-matching-with.html"&gt;Match a string with multiple strings&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-addrange-to.html"&gt;Add Range to Collection&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-force-download.html"&gt;Force Download a File&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/this-extension-method-is-to-convert.html"&gt;Generate HTML Table from IEnumerable&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-log-exception.html"&gt;Log / Email the Exception&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-resize-image.html"&gt;Resize the Image&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-throw-exception.html"&gt;Throw an exception if argument / parameter of function is null&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-send-email.html"&gt;Send Email&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-clone.html"&gt;Clone The Object&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-replace-items-in.html"&gt;Replace The items in Collection&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-from-ienumerable.html"&gt;Generate specified separated string from IEnumerable&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-slice-of.html"&gt;Get Slice of collection form a collection&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-execute-if-not.html"&gt;Execute If Not Null&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-value-exists.html"&gt;Value Exists Between Range&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-convert-enum-to.html"&gt;Convert Enum To Dictionary&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-isnull.html"&gt;Check Is NUll&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-type-conversion.html"&gt;Type Conversion&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-convert-to.html"&gt;Convert To Integer and Return 0 if failure&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-convert-to_30.html"&gt;Convert To Double and Return 0 if failure&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-extensions-for.html"&gt;Extension Methods for Datatable and DataReader&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-json.html"&gt;Extension Methods for JSON&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-date-and-time.html"&gt;Extension Methods for Date and Time&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-string-extension.html"&gt;Extension Methods for String&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-http-extension.html"&gt;Extension Methods for HTTP&lt;/a&gt;
&lt;br/&gt;
&lt;a href="http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-cookie-extension.html"&gt;Extension Methods for Cookie&lt;/a&gt;


&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-1531849529301631291?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0QrCFhJcI3KkLZ1ppIYM8WbINpI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0QrCFhJcI3KkLZ1ppIYM8WbINpI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0QrCFhJcI3KkLZ1ppIYM8WbINpI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0QrCFhJcI3KkLZ1ppIYM8WbINpI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/TXtMI9iqW48" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/TXtMI9iqW48/best-extension-methods.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-4049665359480612785</guid><pubDate>Mon, 30 Jan 2012 18:36:00 +0000</pubDate><atom:updated>2012-01-30T10:36:14.422-08:00</atom:updated><title>Best Extension Methods: Cookie Extension Methods</title><description>Best Cookies Extension Methods

&lt;pre name="code" class="c#"&gt;
public static class CookieExtensions
{

    /// &lt;summary&gt;
    /// Sets a persistent cookie which expires after the given number of days
    /// &lt;/summary&gt;
    /// &lt;param name="doc"&gt;The HtmDocument to extend&lt;/param&gt;
    /// &lt;param name="key"&gt;the cookie key&lt;/param&gt;
    /// &lt;param name="value"&gt;the cookie value&lt;/param&gt;
    /// &lt;param name="days"&gt;The number of days before the cookie expires&lt;/param&gt;
    public static void SetCookie(this HtmlDocument doc, string key, string value, int days)
    {
        DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(days);
        SetCookie(doc, key, value, expiration);
    }

    /// &lt;summary&gt;
    /// Sets a persistent cookie with an expiration date
    /// &lt;/summary&gt;
    /// &lt;param name="doc"&gt;The HtmDocument to extend&lt;/param&gt;
    /// &lt;param name="key"&gt;the cookie key&lt;/param&gt;
    /// &lt;param name="value"&gt;the cookie value&lt;/param&gt;
    public static void SetCookie(this HtmlDocument doc, string key, string value, DateTime expiration)
    {
        string oldCookie = doc.GetProperty("cookie") as String;
        string cookie = String.Format("{0}={1};expires={2}", key, value, expiration.ToString("R"));
        doc.SetProperty("cookie", cookie);
    }

    /// &lt;summary&gt;
    /// Retrieves an existing cookie
    /// &lt;/summary&gt;
    /// &lt;param name="doc"&gt;The HtmDocument to extend&lt;/param&gt;
    /// &lt;param name="key"&gt;cookie key&lt;/param&gt;
    /// &lt;returns&gt;null if the cookie does not exist, otherwise the cookie value&lt;/returns&gt;
    public static string GetCookie(this HtmlDocument doc, string key)
    {
        string[] cookies = doc.Cookies.Split(';');
        key += '=';
        foreach (string cookie in cookies)
        {
            string cookieStr = cookie.Trim();
            if (cookieStr.StartsWith(key, StringComparison.OrdinalIgnoreCase))
            {
                string[] vals = cookieStr.Split('=');

                if (vals.Length &gt;= 2)
                {
                    return vals[1];
                }

                return string.Empty;
            }
        }

        return null;
    }

    /// &lt;summary&gt;
    /// Deletes a specified cookie by setting its value to empty and expiration to -1 days
    /// &lt;/summary&gt;
    /// &lt;param name="doc"&gt;The HtmDocument to extend&lt;/param&gt;
    /// &lt;param name="key"&gt;the cookie key to delete&lt;/param&gt;
    public static void DeleteCookie(this HtmlDocument doc, string key)
    {
        string oldCookie = doc.GetProperty("cookie") as String;
        DateTime expiration = DateTime.UtcNow - TimeSpan.FromDays(1);
        string cookie = String.Format("{0}=;expires={1}", key, expiration.ToString("R"));
        doc.SetProperty("cookie", cookie);
    }
}

&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-4049665359480612785?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ud_ZlFVbKgycNutVwo6b1QIsRb8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ud_ZlFVbKgycNutVwo6b1QIsRb8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ud_ZlFVbKgycNutVwo6b1QIsRb8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ud_ZlFVbKgycNutVwo6b1QIsRb8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/zr-Quw72emw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/zr-Quw72emw/best-extension-methods-cookie-extension.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-cookie-extension.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-7225318523300748912</guid><pubDate>Mon, 30 Jan 2012 18:34:00 +0000</pubDate><atom:updated>2012-01-30T10:34:37.389-08:00</atom:updated><title>Best Extension Methods: HTTP Extension Methods</title><description>Best Http Extension Methods


&lt;pre name="code" class="c#"&gt;
public static class HttpExtension
{
    public static string HtmlEncode(this string data)
    {
        return HttpUtility.HtmlEncode(data);
    }

    public static string HtmlDecode(this string data)
    {
        return HttpUtility.HtmlDecode(data);
    }

    public static NameValueCollection ParseQueryString(this string query)
    {
        return HttpUtility.ParseQueryString(query);
    }

    public static string UrlEncode(this string url)
    {
        return HttpUtility.UrlEncode(url);
    }

    public static string UrlDecode(this string url)
    {
        return HttpUtility.UrlDecode(url);
    }

    public static string UrlPathEncode(this string url)
    {
        return HttpUtility.UrlPathEncode(url);
    }
}


&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-7225318523300748912?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Wiqa7D-TqipCbF4yd0lC81REC0c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Wiqa7D-TqipCbF4yd0lC81REC0c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Wiqa7D-TqipCbF4yd0lC81REC0c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Wiqa7D-TqipCbF4yd0lC81REC0c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/DpnPCQWzW50" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/DpnPCQWzW50/best-extension-methods-http-extension.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-http-extension.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-4277936384900530274</guid><pubDate>Mon, 30 Jan 2012 18:33:00 +0000</pubDate><atom:updated>2012-01-30T10:33:12.552-08:00</atom:updated><title>Best Extension Methods: String Extension Methods</title><description>Best String Extension Methods


&lt;pre name="code" class="c#"&gt;

public static class StringExtensions
{
    /// &lt;summary&gt;
    /// if the string is NULL, converts it to string.empty. Helpful when trying to avoid null conditions.
    /// &lt;/summary&gt;
    /// &lt;param name="inString"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static string IsNullThenEmpty(this string inString)
    {
        if (inString == null)
            return string.Empty;
        else
            return inString;
    }			

    public static string[] GetStringInBetween(this string strSource, string strBegin, string strEnd, bool includeBegin, bool includeEnd)
    {

        string[] result = { "", "" };

        int iIndexOfBegin = strSource.IndexOf(strBegin);

        if (iIndexOfBegin != -1)
        {

            // include the Begin string if desired

            if (includeBegin)

                iIndexOfBegin -= strBegin.Length;

            strSource = strSource.Substring(iIndexOfBegin

                + strBegin.Length);

            int iEnd = strSource.IndexOf(strEnd);

            if (iEnd != -1)
            {

                // include the End string if desired

                if (includeEnd)

                    iEnd += strEnd.Length;

                result[0] = strSource.Substring(0, iEnd);

                // advance beyond this segment

                if (iEnd + strEnd.Length &lt; strSource.Length)

                    result[1] = strSource.Substring(iEnd

                        + strEnd.Length);

            }

        }

        else

            // stay where we are

            result[1] = strSource;

        return result;

    }

    public static T ToEnum&lt;T&gt;(this string value)
       where T : struct
    {
       
        //Debug.Assert(!string.IsNullOrEmpty(value));
        return (T)Enum.Parse(typeof(T), value, true);
    }
    public static string Nl2Br(this string s)
    {
        return s.Replace("\r\n", "&lt;br /&gt;").Replace("\n", "&lt;br /&gt;");
    }
    public static string Format(this string format, object arg, params object[] additionalArgs)
    {
        if (additionalArgs == null || additionalArgs.Length == 0)
        {
            return string.Format(format, arg);
        }
        else
        {
            return string.Format(format, new object[] { arg }.Concat(additionalArgs).ToArray());
        }
    }
    public static bool ContainsAny(this string theString, char[] characters)
    {
        foreach (char character in characters)
        {
            if (theString.Contains(character.ToString()))
            {
                return true;
            }
        }
        return false;
    }

    /// &lt;summary&gt;
    /// Strip a string of the specified substring.
    /// &lt;/summary&gt;
    /// &lt;param name="s"&gt;the string to process&lt;/param&gt;
    /// &lt;param name="subString"&gt;substring to remove&lt;/param&gt;
    /// &lt;example&gt;
    /// string s = "abcde";
    /// 
    /// s = s.Strip("bcd");  //s becomes 'ae;
    /// &lt;/example&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static string Strip(this string s, string subString)
    {
        s = s.Replace(subString, "");

        return s;
    }
    /// &lt;summary&gt;
    /// Strip a string of the specified character.
    /// &lt;/summary&gt;
    /// &lt;param name="s"&gt;the string to process&lt;/param&gt;
    /// &lt;param name="char"&gt;character to remove from the string&lt;/param&gt;
    /// &lt;example&gt;
    /// string s = "abcde";
    /// 
    /// s = s.Strip('b');  //s becomes 'acde;
    /// &lt;/example&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static string Strip(this string s, char character)
    {
        s = s.Replace(character.ToString(), "");

        return s;
    }

    /// &lt;summary&gt;
    /// Strip a string of the specified characters.
    /// &lt;/summary&gt;
    /// &lt;param name="s"&gt;the string to process&lt;/param&gt;
    /// &lt;param name="chars"&gt;list of characters to remove from the string&lt;/param&gt;
    /// &lt;example&gt;
    /// string s = "abcde";
    /// 
    /// s = s.Strip('a', 'd');  //s becomes 'bce;
    /// &lt;/example&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static string Strip(this string s, params char[] chars)
    {
        foreach (char c in chars)
        {
            s = s.Replace(c.ToString(), "");
        }

        return s;
    }


    /// &lt;summary&gt;
    /// Splits a string into a NameValueCollection, where each "namevalue" is separated by
    /// the "OuterSeparator". The parameter "NameValueSeparator" sets the split between Name and Value.
    /// Example: 
    ///             String str = "param1=value1;param2=value2";
    ///             NameValueCollection nvOut = str.ToNameValueCollection(';', '=');
    ///             
    /// The result is a NameValueCollection where:
    ///             key[0] is "param1" and value[0] is "value1"
    ///             key[1] is "param2" and value[1] is "value2"
    /// &lt;/summary&gt;
    /// &lt;param name="str"&gt;String to process&lt;/param&gt;
    /// &lt;param name="OuterSeparator"&gt;Separator for each "NameValue"&lt;/param&gt;
    /// &lt;param name="NameValueSeparator"&gt;Separator for Name/Value splitting&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static NameValueCollection ToNameValueCollection(this String str, Char OuterSeparator, Char NameValueSeparator)
    {
        NameValueCollection nvText = null;
        str = str.TrimEnd(OuterSeparator);
        if (!String.IsNullOrEmpty(str))
        {
            String[] arrStrings = str.TrimEnd(OuterSeparator).Split(OuterSeparator);

            foreach (String s in arrStrings)
            {
                Int32 posSep = s.IndexOf(NameValueSeparator);
                String name = s.Substring(0, posSep);
                String value = s.Substring(posSep + 1);
                if (nvText == null)
                    nvText = new NameValueCollection();
                nvText.Add(name, value);
            }
        }
        return nvText;
    }
    /// &lt;summary&gt;
    /// Truncates the string to a specified length and replace the truncated to a ...
    /// &lt;/summary&gt;
    /// &lt;param name="text"&gt;string that will be truncated&lt;/param&gt;
    /// &lt;param name="maxLength"&gt;total length of characters to maintain before the truncate happens&lt;/param&gt;
    /// &lt;returns&gt;truncated string&lt;/returns&gt;
    public static string Truncate(this string text, int maxLength)
    {
        // replaces the truncated string to a ...
        const string suffix = "...";
        string truncatedString = text;

        if (maxLength &lt;= 0) return truncatedString;
        int strLength = maxLength - suffix.Length;

        if (strLength &lt;= 0) return truncatedString;

        if (text == null || text.Length &lt;= maxLength) return truncatedString;

        truncatedString = text.Substring(0, strLength);
        truncatedString = truncatedString.TrimEnd();
        truncatedString += suffix;
        return truncatedString;
    }
    /// &lt;summary&gt;
    /// Returns the last few characters of the string with a length
    /// specified by the given parameter. If the string's length is less than the 
    /// given length the complete string is returned. If length is zero or 
    /// less an empty string is returned
    /// &lt;/summary&gt;
    /// &lt;param name="s"&gt;the string to process&lt;/param&gt;
    /// &lt;param name="length"&gt;Number of characters to return&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static string Right(this string s, int length)
    {
        length = Math.Max(length, 0);

        if (s.Length &gt; length)
        {
            return s.Substring(s.Length - length, length);
        }
        else
        {
            return s;
        }
    }
    public static String left(this String s, int len)
    {
        return s.Substring(0, Math.Min(len, s.Length));
    }
    public static DateTime ToDateFromDDMMYYYY(this string date)
    {
        return DateTime.ParseExact(date, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);

    }
    //Format string to Title case
    public static string ToTitleCase(this string mText)
    {
        if (mText == null) return mText;

        System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
        System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;

        // TextInfo.ToTitleCase only operates on the string if is all lower case, otherwise it returns the string unchanged.
        return textInfo.ToTitleCase(mText.ToLower());
    }
    /// &lt;summary&gt;
    /// Parses a string into an Enum
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;The type of the Enum&lt;/typeparam&gt;
    /// &lt;param name="value"&gt;String value to parse&lt;/param&gt;
    /// &lt;returns&gt;The Enum corresponding to the stringExtensions&lt;/returns&gt;
    public static T EnumParse&lt;T&gt;(this string value)
    {
        return EnumParse&lt;T&gt;(value, false);
    }

    public static T EnumParse&lt;T&gt;(this string value, bool ignorecase)
    {

        if (value == null)
        {
            throw new ArgumentNullException("value");
        }

        value = value.Trim();

        if (value.Length == 0)
        {
            throw new ArgumentException("Must specify valid information for parsing in the string.", "value");
        }

        Type t = typeof(T);

        if (!t.IsEnum)
        {
            throw new ArgumentException("Type provided must be an Enum.", "T");
        }

        return (T)Enum.Parse(t, value, ignorecase);
    }
    // Enable quick and more natural string.Format calls
    public static string F(this string s, params object[] args)
    {
        return string.Format(s, args);
    }
    public static DateTime? ToDateTime(this string source)
    {
        if (!string.IsNullOrEmpty(source))
        {
            return Convert.ToDateTime(source);
        }
        return null;
    }
    public static int? ToNullableInt(this string source)
    {
        var i = 0;
        return int.TryParse(source, out i) ? (int?)i : null;
    }
    public static string ToPlural(this string singular)
    {
        // Multiple words in the form A of B : Apply the plural to the first word only (A)
        int index = singular.LastIndexOf(" of ");
        if (index &gt; 0) return (singular.Substring(0, index)) + singular.Remove(0, index).ToPlural();

        // single Word rules
        //sibilant ending rule
        if (singular.EndsWith("sh")) return singular + "es";
        if (singular.EndsWith("ch")) return singular + "es";
        if (singular.EndsWith("us")) return singular + "es";
        if (singular.EndsWith("ss")) return singular + "es";
        //-ies rule
        if (singular.EndsWith("y")) return singular.Remove(singular.Length - 1, 1) + "ies";
        // -oes rule
        if (singular.EndsWith("o")) return singular.Remove(singular.Length - 1, 1) + "oes";
        // -s suffix rule
        return singular + "s";
    }

    public static bool IsValidEmailAddress(this string s)
    {
        Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
        return regex.IsMatch(s);
    }
    /// &lt;summary&gt;
    /// Converts a string into a "SecureString"
    /// &lt;/summary&gt;
    /// &lt;param name="str"&gt;Input String&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static System.Security.SecureString ToSecureString(this String str)
    {
        System.Security.SecureString secureString = new System.Security.SecureString();
        foreach (Char c in str)
            secureString.AppendChar(c);

        return secureString;
    }
    public static string ToProperCase(this string text)
    {
        System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
        System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
        return textInfo.ToTitleCase(text);
    }
    public static bool IsNumeric(this string theValue)
    {
        long retNum;
        return long.TryParse(theValue, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
    }
    public static bool IsNotNullOrEmpty(this string input)
    {
        return !String.IsNullOrEmpty(input);
    }
    public static bool IsNullOrEmpty(this string input)
    {
        return String.IsNullOrEmpty(input);
    }
    public static bool IsNotNullOrEmptyOrSpace(this string input)
    {
        if (!String.IsNullOrEmpty(input))
        {
            return !String.IsNullOrEmpty(input.Trim());
        }
        else
        {
            return true;
        }
    }
    public static bool IsNullOrEmptyOrSpace(this string input)
    {
        if (!String.IsNullOrEmpty(input))
        {
            return String.IsNullOrEmpty(input.Trim());
        }
        else
        {
            return true;
        }
    }

    /// &lt;summary&gt;
    /// Count all words in a given string
    /// &lt;/summary&gt;
    /// &lt;param name="input"&gt;string to begin with&lt;/param&gt;
    /// &lt;returns&gt;int&lt;/returns&gt;
    public static int WordCount(this string input)
    {
        var count = 0;
        try
        {
            // Exclude whitespaces, Tabs and line breaks
            var re = new Regex(@"[^\s]+");
            var matches = re.Matches(input);
            count = matches.Count;
        }
        catch
        {
        }
        return count;
    }
}

&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-4277936384900530274?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UEloVdtEyhbjr23XTCOSHh2wSs8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UEloVdtEyhbjr23XTCOSHh2wSs8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UEloVdtEyhbjr23XTCOSHh2wSs8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UEloVdtEyhbjr23XTCOSHh2wSs8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/y2ZtEip__Pg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/y2ZtEip__Pg/best-extension-methods-string-extension.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-string-extension.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-5966453321788669329</guid><pubDate>Mon, 30 Jan 2012 18:31:00 +0000</pubDate><atom:updated>2012-01-30T10:31:40.300-08:00</atom:updated><title>Best Extension Methods: Date and Time</title><description>Best Extension Methods for Date and time


&lt;pre name="code" class="c#"&gt;

public static class DateExtensions
{

    /// &lt;summary&gt;
    /// DateDiff in SQL style. 
    /// Datepart implemented: 
    ///     "year" (abbr. "yy", "yyyy"), 
    ///     "quarter" (abbr. "qq", "q"), 
    ///     "month" (abbr. "mm", "m"), 
    ///     "day" (abbr. "dd", "d"), 
    ///     "week" (abbr. "wk", "ww"), 
    ///     "hour" (abbr. "hh"), 
    ///     "minute" (abbr. "mi", "n"), 
    ///     "second" (abbr. "ss", "s"), 
    ///     "millisecond" (abbr. "ms").
    /// &lt;/summary&gt;
    /// &lt;param name="DatePart"&gt;&lt;/param&gt;
    /// &lt;param name="EndDate"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static Int64 DateDiff(this DateTime StartDate, String DatePart, DateTime EndDate)
    {
        Int64 DateDiffVal = 0;
        System.Globalization.Calendar cal = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;
        TimeSpan ts = new TimeSpan(EndDate.Ticks - StartDate.Ticks);
        switch (DatePart.ToLower().Trim())
        {
            #region year
            case "year":
            case "yy":
            case "yyyy":
                DateDiffVal = (Int64)(cal.GetYear(EndDate) - cal.GetYear(StartDate));
                break;
            #endregion

            #region quarter
            case "quarter":
            case "qq":
            case "q":
                DateDiffVal = (Int64)((((cal.GetYear(EndDate)
                                    - cal.GetYear(StartDate)) * 4)
                                    + ((cal.GetMonth(EndDate) - 1) / 3))
                                    - ((cal.GetMonth(StartDate) - 1) / 3));
                break;
            #endregion

            #region month
            case "month":
            case "mm":
            case "m":
                DateDiffVal = (Int64)(((cal.GetYear(EndDate)
                                    - cal.GetYear(StartDate)) * 12
                                    + cal.GetMonth(EndDate))
                                    - cal.GetMonth(StartDate));
                break;
            #endregion

            #region day
            case "day":
            case "d":
            case "dd":
                DateDiffVal = (Int64)ts.TotalDays;
                break;
            #endregion

            #region week
            case "week":
            case "wk":
            case "ww":
                DateDiffVal = (Int64)(ts.TotalDays / 7);
                break;
            #endregion

            #region hour
            case "hour":
            case "hh":
                DateDiffVal = (Int64)ts.TotalHours;
                break;
            #endregion

            #region minute
            case "minute":
            case "mi":
            case "n":
                DateDiffVal = (Int64)ts.TotalMinutes;
                break;
            #endregion

            #region second
            case "second":
            case "ss":
            case "s":
                DateDiffVal = (Int64)ts.TotalSeconds;
                break;
            #endregion

            #region millisecond
            case "millisecond":
            case "ms":
                DateDiffVal = (Int64)ts.TotalMilliseconds;
                break;
            #endregion

            default:
                throw new Exception(String.Format("DatePart \"{0}\" is unknown", DatePart));
        }
        return DateDiffVal;
    }
    public static string ToStringDDMMYYYYFromDate(this DateTime date)
    {
        if (date == null)
        {
            return "";
        }
        else
        {
            return date.ToString("dd/MM/yyyy");

        }
    }
    public static string ToStringDDMMYYYYFromDate(this DateTime? date)
    {
        if (date == null)
        {
            return "";
        }
        else
        {
            return ((DateTime)date).ToString("dd-MM-yyyy");

        }
    }
    static public int Age(this DateTime dateOfBirth)
    {
        if (DateTime.Today.Month &lt; dateOfBirth.Month ||
        DateTime.Today.Month == dateOfBirth.Month &amp;&amp;
         DateTime.Today.Day &lt; dateOfBirth.Day)
        {
            return DateTime.Today.Year - dateOfBirth.Year - 1;
        }
        else
            return DateTime.Today.Year - dateOfBirth.Year;
    }
    public static string ToFriendlyDateString(this DateTime Date)
    {
        string FormattedDate = "";
        if (Date.Date == DateTime.Today)
        {
            FormattedDate = "Today";
        }
        else if (Date.Date == DateTime.Today.AddDays(-1))
        {
            FormattedDate = "Yesterday";
        }
        else if (Date.Date &gt; DateTime.Today.AddDays(-6))
        {
            // *** Show the Day of the week
            FormattedDate = Date.ToString("dddd").ToString();
        }
        else
        {
            FormattedDate = Date.ToString("MMMM dd, yyyy");
        }

        //append the time portion to the output
        FormattedDate += " @ " + Date.ToString("t").ToLower();
        return FormattedDate;
    }
    public static bool IsWeekend(this DayOfWeek d)
    {
        return !d.IsWeekday();
    }

    public static bool IsWeekday(this DayOfWeek d)
    {
        switch (d)
        {
            case DayOfWeek.Sunday:
            case DayOfWeek.Saturday: return false;

            default: return true;
        }
    }

    public static DateTime AddWorkdays(this DateTime d, int days)
    {
        // start from a weekday
        while (d.DayOfWeek.IsWeekday()) d = d.AddDays(1.0);
        for (int i = 0; i &lt; days; ++i)
        {
            d = d.AddDays(1.0);
            while (d.DayOfWeek.IsWeekday()) d = d.AddDays(1.0);
        }
        return d;
    }
    public static string FirstDayOfMonth(this DateTime date)
    {
        return new DateTime(date.Year, date.Month, 1).ToString("MM/dd/yyyy");
    }

    public static string LastDayOfMonth(this DateTime date)
    {
        return new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 1).AddDays(-1).ToString("MM/dd/yyyy");
    }
    /// &lt;summary&gt;
    /// Converts a regular DateTime to a RFC822 date string.
    /// &lt;/summary&gt;
    /// &lt;returns&gt;The specified date formatted as a RFC822 date string.&lt;/returns&gt;
    public static string ToRFC822DateString(this DateTime date)
    {
        int offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
        string timeZone = "+" + offset.ToString().PadLeft(2, '0');
        if (offset &lt; 0)
        {
            int i = offset * -1;
            timeZone = "-" + i.ToString().PadLeft(2, '0');
        }
        return date.ToString("ddd, dd MMM yyyy HH:mm:ss " + timeZone.PadRight(5, '0'), System.Globalization.CultureInfo.GetCultureInfo("en-US"));
    }
}

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-5966453321788669329?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FoY8kj-Xph9nIBNGtU4diOArT1g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FoY8kj-Xph9nIBNGtU4diOArT1g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FoY8kj-Xph9nIBNGtU4diOArT1g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FoY8kj-Xph9nIBNGtU4diOArT1g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/J_mVXqUHvpA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/J_mVXqUHvpA/best-extension-methods-date-and-time.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-date-and-time.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-7689186907844125719</guid><pubDate>Mon, 30 Jan 2012 18:30:00 +0000</pubDate><atom:updated>2012-01-30T10:30:16.618-08:00</atom:updated><title>Best Extension Methods: JSON</title><description>These are best extension methods for JSON


&lt;pre name="code" class="c#"&gt;
public static class Json
{

    public static string ToJson(this object obj)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        return serializer.Serialize(obj);
    }

    public static string ToJson(this object obj, int recursionDepth)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        serializer.RecursionLimit = recursionDepth;
        return serializer.Serialize(obj);
    }

    public static T FromJson&lt;T&gt;(this object obj)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        return serializer.Deserialize&lt;T&gt;(obj as string);
    }
}

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-7689186907844125719?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7OZlH1nblJWsuJ9MC25OGrXQ5vg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7OZlH1nblJWsuJ9MC25OGrXQ5vg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7OZlH1nblJWsuJ9MC25OGrXQ5vg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7OZlH1nblJWsuJ9MC25OGrXQ5vg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/og2UNI55LmQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/og2UNI55LmQ/best-extension-methods-json.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-json.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-5409639874704081441</guid><pubDate>Mon, 30 Jan 2012 18:28:00 +0000</pubDate><atom:updated>2012-01-30T10:28:51.636-08:00</atom:updated><title>Best Extension Methods: Extensions for Datatable and Datareader</title><description>Best Extension Methods for DataTable and DataReader

&lt;pre name="code" class="c#"&gt;
public static class DataTableReaderExtension
{
    #region Select Distinct
    /// &lt;summary&gt;
    /// "SELECT DISTINCT" over a DataTable
    /// &lt;/summary&gt;
    /// &lt;param name="SourceTable"&gt;Input DataTable&lt;/param&gt;
    /// &lt;param name="FieldNames"&gt;Fields to select (distinct)&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static DataTable SelectDistinct(this DataTable SourceTable, String FieldName)
    {
        return SelectDistinct(SourceTable, FieldName, String.Empty);
    }

    /// &lt;summary&gt;
    ///"SELECT DISTINCT" over a DataTable
    /// &lt;/summary&gt;
    /// &lt;param name="SourceTable"&gt;Input DataTable&lt;/param&gt;
    /// &lt;param name="FieldNames"&gt;Fields to select (distinct)&lt;/param&gt;
    /// &lt;param name="Filter"&gt;Optional filter to be applied to the selection&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static DataTable SelectDistinct(this DataTable SourceTable, String FieldNames, String Filter)
    {
        DataTable dt = new DataTable();
        String[] arrFieldNames = FieldNames.Replace(" ", "").Split(',');
        foreach (String s in arrFieldNames)
        {
            if (SourceTable.Columns.Contains(s))
                dt.Columns.Add(s, SourceTable.Columns[s].DataType);
            else
                throw new Exception(String.Format("The column {0} does not exist.", s));
        }

        Object[] LastValues = null;
        foreach (DataRow dr in SourceTable.Select(Filter, FieldNames))
        {
            Object[] NewValues = GetRowFields(dr, arrFieldNames);
            if (LastValues == null || !(ObjectComparison(LastValues, NewValues)))
            {
                LastValues = NewValues;
                dt.Rows.Add(LastValues);
            }
        }

        return dt;
    }
    #endregion

    #region Private Methods
    private static Object[] GetRowFields(DataRow dr, String[] arrFieldNames)
    {
        if (arrFieldNames.Length == 1)
            return new Object[] { dr[arrFieldNames[0]] };
        else
        {
            ArrayList itemArray = new ArrayList();
            foreach (String field in arrFieldNames)
                itemArray.Add(dr[field]);

            return itemArray.ToArray();
        }
    }

    /// &lt;summary&gt;
    /// Compares two values to see if they are equal. Also compares DBNULL.Value.
    /// &lt;/summary&gt;
    /// &lt;param name="A"&gt;Object A&lt;/param&gt;
    /// &lt;param name="B"&gt;Object B&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    private static Boolean ObjectComparison(Object a, Object b)
    {
        if (a == DBNull.Value &amp;&amp; b == DBNull.Value) //  both are DBNull.Value
            return true;
        if (a == DBNull.Value || b == DBNull.Value) //  only one is DBNull.Value
            return false;
        return (a.Equals(b));  // value type standard comparison
    }

    /// &lt;summary&gt;
    /// Compares two value arrays to see if they are equal. Also compares DBNULL.Value.
    /// &lt;/summary&gt;
    /// &lt;param name="A"&gt;Object Array A&lt;/param&gt;
    /// &lt;param name="B"&gt;Object Array B&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    private static Boolean ObjectComparison(Object[] a, Object[] b)
    {
        Boolean retValue = true;
        Boolean singleCheck = false;

        if (a.Length == b.Length)
            for (Int32 i = 0; i &lt; a.Length; i++)
            {
                if (!(singleCheck = ObjectComparison(a[i], b[i])))
                {
                    retValue = false;
                    break;
                }
                retValue = retValue &amp;&amp; singleCheck;
            }

        return retValue;
    }
    #endregion
    /// &lt;summary&gt;
    /// Checks if a column exists in the DataReader
    /// &lt;/summary&gt;
    /// &lt;param name="dr"&gt;DataReader&lt;/param&gt;
    /// &lt;param name="ColumnName"&gt;Name of the column to find&lt;/param&gt;
    /// &lt;returns&gt;Returns true if the column exists in the DataReader, else returns false&lt;/returns&gt;
    public static Boolean ColumnExists(this IDataReader dr, String ColumnName)
    {
        for (Int32 i = 0; i &lt; dr.FieldCount; i++)
            if (dr.GetName(i).Equals(ColumnName, StringComparison.OrdinalIgnoreCase))
                return true;

        return false;
    }




}

&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-5409639874704081441?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FwupxYkPCgJrGsX-cQzE493-rA8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FwupxYkPCgJrGsX-cQzE493-rA8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FwupxYkPCgJrGsX-cQzE493-rA8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FwupxYkPCgJrGsX-cQzE493-rA8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/OGIkeb0wOIs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/OGIkeb0wOIs/best-extension-methods-extensions-for.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-extensions-for.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-6995406424127615259</guid><pubDate>Mon, 30 Jan 2012 18:26:00 +0000</pubDate><atom:updated>2012-01-30T10:26:37.553-08:00</atom:updated><title>Best Extension Methods: Slice of Collection</title><description>This Extension method is to get a slice of collection from a collection.




&lt;pre name="code" class="c#"&gt;
  public static IEnumerable&lt;T&gt; Slice&lt;T&gt;(this IEnumerable&lt;T&gt; collection, int start, int end)
        {
            int index = 0;
            int count = 0;

            if (collection == null)
                throw new ArgumentNullException("collection");

            // Optimise item count for ICollection interfaces.
            if (collection is ICollection&lt;T&gt;)
                count = ((ICollection&lt;T&gt;)collection).Count;
            else if (collection is ICollection)
                count = ((ICollection)collection).Count;
            else
                count = collection.Count();

            // Get start/end indexes, negative numbers start at the end of the collection.
            if (start &lt; 0)
                start += count;

            if (end &lt; 0)
                end += count;

            foreach (var item in collection)
            {
                if (index &gt;= end)
                    yield break;

                if (index &gt;= start)
                    yield return item;

                ++index;
            }
        }
    }

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-6995406424127615259?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ysJIZO-djCb_ytPYOvG4vZEGETk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ysJIZO-djCb_ytPYOvG4vZEGETk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ysJIZO-djCb_ytPYOvG4vZEGETk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ysJIZO-djCb_ytPYOvG4vZEGETk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/R8QHahEcR1c" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/R8QHahEcR1c/best-extension-methods-slice-of.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-slice-of.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-6866935621905738916</guid><pubDate>Mon, 30 Jan 2012 18:24:00 +0000</pubDate><atom:updated>2012-01-30T10:24:28.141-08:00</atom:updated><title>Best Extension Methods: From IEnumerable To String</title><description>This extension method creates a string with specified separator from an IEnumerable List.


&lt;pre name="code" class="c#"&gt;
/// &lt;summary&gt;
        /// Concatenates a specified separator String between each element of a specified enumeration, yielding a single concatenated string.
        /// &lt;/summary&gt;
        /// &lt;typeparam name="T"&gt;any object&lt;/typeparam&gt;
        /// &lt;param name="list"&gt;The enumeration&lt;/param&gt;
        /// &lt;param name="separator"&gt;A String&lt;/param&gt;
        /// &lt;returns&gt;A String consisting of the elements of value interspersed with the separator string.&lt;/returns&gt;
        public static string ToString&lt;T&gt;(this IEnumerable&lt;T&gt; list, string separator)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var obj in list)
            {
                if (sb.Length &gt; 0)
                {
                    sb.Append(separator);
                }
                sb.Append(obj);
            }
            return sb.ToString();
        }

&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-6866935621905738916?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Dl0iY3ppMTu79-6o0wmg5A_P5h4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dl0iY3ppMTu79-6o0wmg5A_P5h4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Dl0iY3ppMTu79-6o0wmg5A_P5h4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Dl0iY3ppMTu79-6o0wmg5A_P5h4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/kl9_jGngNdI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/kl9_jGngNdI/best-extension-methods-from-ienumerable.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-from-ienumerable.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-4839382184969686585</guid><pubDate>Mon, 30 Jan 2012 18:21:00 +0000</pubDate><atom:updated>2012-01-30T10:21:44.555-08:00</atom:updated><title>Best Extension Methods: Replace Items in Collection</title><description>This extension method replaces an item in a collection that implements the IList interface.

&lt;pre name="code" class="c#"&gt;
   /// &lt;summary&gt;
        /// This extension method replaces an item in a collection that implements the IList interface.
        /// &lt;/summary&gt;
        /// &lt;typeparam name="T"&gt;The type of the field that we are manipulating&lt;/typeparam&gt;
        /// &lt;param name="thisList"&gt;The input list&lt;/param&gt;
        /// &lt;param name="position"&gt;The position of the old item&lt;/param&gt;
        /// &lt;param name="item"&gt;The item we are goint to put in it's place&lt;/param&gt;
        /// &lt;returns&gt;True in case of a replace, false if failed&lt;/returns&gt;
        public static bool Replace&lt;T&gt;(this IList&lt;T&gt; thisList, int position, T item)
        {
            if (position &gt; thisList.Count - 1)
                return false;
            // only process if inside the range of this list

            thisList.RemoveAt(position);
            // remove the old item
            thisList.Insert(position, item);
            // insert the new item at its position
            return true;
            // return success
        }

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-4839382184969686585?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/an-sPVMMrO_jnZcjr7aFmDq0rq4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/an-sPVMMrO_jnZcjr7aFmDq0rq4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/an-sPVMMrO_jnZcjr7aFmDq0rq4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/an-sPVMMrO_jnZcjr7aFmDq0rq4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/X8CwzScV9VE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/X8CwzScV9VE/best-extension-methods-replace-items-in.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-replace-items-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-8085064398951010494</guid><pubDate>Mon, 30 Jan 2012 18:18:00 +0000</pubDate><atom:updated>2012-01-30T10:18:17.383-08:00</atom:updated><title>Best Extension Methods: Clone</title><description>This extension method to get a clone of an object

&lt;pre name="code" class="c#"&gt;
    /// &lt;summary&gt;
    /// Makes a copy from the object.
    /// Doesn't copy the reference memory, only data.
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;Type of the return object.&lt;/typeparam&gt;
    /// &lt;param name="item"&gt;Object to be copied.&lt;/param&gt;
    /// &lt;returns&gt;Returns the copied object.&lt;/returns&gt;
    public static T Clone&lt;T&gt;(this object item)
    {
        if (item != null)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();

            formatter.Serialize(stream, item);
            stream.Seek(0, SeekOrigin.Begin);

            T result = (T)formatter.Deserialize(stream);

            stream.Close();

            return result;
        }
        else
            return default(T);
    }

&lt;/pre&gt;
&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-8085064398951010494?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/L_V9QTxo237Siy0-eh5rVqPzivQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L_V9QTxo237Siy0-eh5rVqPzivQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/L_V9QTxo237Siy0-eh5rVqPzivQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L_V9QTxo237Siy0-eh5rVqPzivQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/PyVD1ClP2JA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/PyVD1ClP2JA/best-extension-methods-clone.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-clone.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-785143905060365415</guid><pubDate>Mon, 30 Jan 2012 18:16:00 +0000</pubDate><atom:updated>2012-01-30T10:16:26.222-08:00</atom:updated><title>Best Extension Methods: Send Email</title><description>If your application need functionality to send email at any time may be send a value of string or may be some exception then this extension method will help you.


&lt;pre name="code" class="c#"&gt;


    /// &lt;summary&gt;
    /// Send an email using the supplied string.
    /// &lt;/summary&gt;
    /// &lt;param name="body"&gt;String that will be used i the body of the email.&lt;/param&gt;
    /// &lt;param name="subject"&gt;Subject of the email.&lt;/param&gt;
    /// &lt;param name="sender"&gt;The email address from which the message was sent.&lt;/param&gt;
    /// &lt;param name="recipient"&gt;The receiver of the email.&lt;/param&gt; 
    /// &lt;param name="server"&gt;The server from which the email will be sent.&lt;/param&gt;  
    /// &lt;returns&gt;A boolean value indicating the success of the email send.&lt;/returns&gt;
    public static bool Email(this string body, string subject, string sender, string recipient, string server)
    {
        try
        {
            // To
            //MailMessage mailMsg = new MailMessage();
            //mailMsg.To.Add(recipient);

            //// From
            //MailAddress mailAddress = new MailAddress(sender);
            //mailMsg.From = mailAddress;

            //// Subject and Body
            //mailMsg.Subject = subject;
            //mailMsg.Body = body;

            //// Init SmtpClient and send
            //SmtpClient smtpClient = new SmtpClient(server);
            //System.Net.NetworkCredential credentials = new System.Net.NetworkCredential();
            //smtpClient.Credentials = credentials;

            //smtpClient.Send(mailMsg);
        }
        catch (Exception ex)
        {
            return false;
        }

        return true;
    }

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-785143905060365415?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XPbeTIukTJUfm5S_xwh853VvZbE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XPbeTIukTJUfm5S_xwh853VvZbE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XPbeTIukTJUfm5S_xwh853VvZbE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XPbeTIukTJUfm5S_xwh853VvZbE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/6Q5TeZYWWAg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/6Q5TeZYWWAg/best-extension-methods-send-email.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-send-email.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-1790252830274498608</guid><pubDate>Mon, 30 Jan 2012 18:13:00 +0000</pubDate><atom:updated>2012-01-30T10:13:56.827-08:00</atom:updated><title>Best Extension Methods: Throw exception argument is Null</title><description>This extension method is for parameters of function where you wants that if a parameter/argument of a function is null then you want an exception to be thrown.

&lt;pre name="code" class="c#"&gt;
//Throw exception if parameters of function is null
    // eg: public Test(string input1)
    //{
    //    input1.ThrowIfArgumentIsNull("input1");
    //}
    public static void ThrowIfArgumentIsNull&lt;T&gt;(this T obj, string parameterName) where T : class
    {
        if (obj == null) throw new ArgumentNullException(parameterName + " not allowed to be null");
    }

&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-1790252830274498608?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/_Ut2hx5IUFAsx424hoLCx37G844/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_Ut2hx5IUFAsx424hoLCx37G844/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/_Ut2hx5IUFAsx424hoLCx37G844/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/_Ut2hx5IUFAsx424hoLCx37G844/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/GcDJ_NLfM2c" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/GcDJ_NLfM2c/best-extension-methods-throw-exception.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-throw-exception.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-9136961164441838020</guid><pubDate>Mon, 30 Jan 2012 18:10:00 +0000</pubDate><atom:updated>2012-01-30T10:10:31.707-08:00</atom:updated><title>Best Extension Methods: Resize Image</title><description>If your site has more work on displaying product images then this extension method will best suit for you application. This extension method is able to resize the image.


&lt;pre name="code" class="c#"&gt;

 public static Image ResizeAndFit(this Image image, Size newSize)
    {
        var sourceIsLandscape = image.Width &gt; image.Height;
        var targetIsLandscape = newSize.Width &gt; newSize.Height;

        var ratioWidth = (double)newSize.Width / (double)image.Width;
        var ratioHeight = (double)newSize.Height / (double)image.Height;

        var ratio = 0.0;

        if (ratioWidth &gt; ratioHeight &amp;&amp; sourceIsLandscape == targetIsLandscape)
            ratio = ratioWidth;
        else
            ratio = ratioHeight;

        int targetWidth = (int)(image.Width * ratio);
        int targetHeight = (int)(image.Height * ratio);

        var bitmap = new Bitmap(newSize.Width, newSize.Height);
        var graphics = Graphics.FromImage((Image)bitmap);

        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

        var offsetX = ((double)(newSize.Width - targetWidth)) / 2;
        var offsetY = ((double)(newSize.Height - targetHeight)) / 2;

        graphics.DrawImage(image, (int)offsetX, (int)offsetY, targetWidth, targetHeight);
        graphics.Dispose();

        return (Image)bitmap;
    }


&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-9136961164441838020?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ceUQrFWVYvjqUNeJa3ahEWLnZzM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ceUQrFWVYvjqUNeJa3ahEWLnZzM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ceUQrFWVYvjqUNeJa3ahEWLnZzM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ceUQrFWVYvjqUNeJa3ahEWLnZzM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/VbVRkKrdNWE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/VbVRkKrdNWE/best-extension-methods-resize-image.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-resize-image.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-2605685670259123022</guid><pubDate>Mon, 30 Jan 2012 18:07:00 +0000</pubDate><atom:updated>2012-01-30T10:07:56.081-08:00</atom:updated><title>Best Extension Methods: Log Exception</title><description>One of the best extension method to log / email the exception of the application.


&lt;pre name="code" class="c#"&gt;
//log exception  like: try
    //{
    //    //Your stuff here
    //}
    //catch(Exception ex)
    //{
    //    ex.Log();
    //}
    public static void Log(this Exception ex, string additionalMessage = "")
    {
        StringBuilder msg = new StringBuilder();

        if (!string.IsNullOrEmpty(additionalMessage))
        {
            msg.Append(additionalMessage);
            msg.Append(Environment.NewLine);
        }

        if (ex != null)
        {
            try
            {
                Exception orgEx = ex;

                msg.Append("Exception:");
                msg.Append(Environment.NewLine);
                while (orgEx != null)
                {
                    msg.Append(orgEx.Message);
                    msg.Append(Environment.NewLine);
                    orgEx = orgEx.InnerException;
                }

                if (ex.Data != null)
                {
                    foreach (object i in ex.Data)
                    {
                        msg.Append("Data :");
                        msg.Append(i.ToString());
                        msg.Append(Environment.NewLine);
                    }
                }

                if (ex.StackTrace != null)
                {
                    msg.Append("StackTrace:");
                    msg.Append(Environment.NewLine);
                    msg.Append(ex.StackTrace.ToString());
                    msg.Append(Environment.NewLine);
                }

                if (ex.Source != null)
                {
                    msg.Append("Source:");
                    msg.Append(Environment.NewLine);
                    msg.Append(ex.Source);
                    msg.Append(Environment.NewLine);
                }

                if (ex.TargetSite != null)
                {
                    msg.Append("TargetSite:");
                    msg.Append(Environment.NewLine);
                    msg.Append(ex.TargetSite.ToString());
                    msg.Append(Environment.NewLine);
                }

                Exception baseException = ex.GetBaseException();
                if (baseException != null)
                {
                    msg.Append("BaseException:");
                    msg.Append(Environment.NewLine);
                    msg.Append(ex.GetBaseException());
                }
            }
            finally
            {
            }
        }
        // log this or email to admin return msg.ToString();
    }
&lt;/pre&gt;

&lt;h3&gt;Compiled BY: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-2605685670259123022?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2QoDW0wZAasLgj30xxGkmav2EWo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2QoDW0wZAasLgj30xxGkmav2EWo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2QoDW0wZAasLgj30xxGkmav2EWo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2QoDW0wZAasLgj30xxGkmav2EWo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/rNmyCXHNTPM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/rNmyCXHNTPM/best-extension-methods-log-exception.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-log-exception.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-5328821119794880971</guid><pubDate>Mon, 30 Jan 2012 18:02:00 +0000</pubDate><atom:updated>2012-01-30T10:05:40.515-08:00</atom:updated><title>Best Extension Methods: From IEnumerable To HTML Table</title><description>This extension method is to convert IEnumerable to HTML Table String. You can use it when you wants to show values of IEnumerable on Screen in form of HTML Table.

&lt;pre name="code" class="c#"&gt;

 public static string ToHtmlTable&lt;T&gt;(this IEnumerable&lt;T&gt; list, string tableSyle, string headerStyle, string rowStyle, string alternateRowStyle)
    {

        var result = new StringBuilder();
        if (String.IsNullOrEmpty(tableSyle))
        {
            result.Append("&amp;lt;table id=\"" + typeof(T).Name + "Table\" &amp;gt;");
        }
        else
        {
            result.Append("&amp;lt;table id=\"" + typeof(T).Name + "Table\" class=\"" + tableSyle + "\" &amp;gt;");
        }

        var propertyArray = typeof(T).GetProperties();
        foreach (var prop in propertyArray)
        {
            if (String.IsNullOrEmpty(headerStyle))
            {
                result.AppendFormat("&amp;lt;th &amp;gt;{0}&amp;lt;/th &amp;gt;", prop.Name);
            }
            else
            {
                result.AppendFormat("&amp;lt;th class=\"{0}\" &amp;gt;{1}&amp;lt;/th &amp;gt;", headerStyle, prop.Name);
            }
        }

        for (int i = 0; i &amp;lt; list.Count(); i++)
        {
            if (!String.IsNullOrEmpty(rowStyle) &amp;&amp; !String.IsNullOrEmpty(alternateRowStyle))
            {
                result.AppendFormat("&amp;lt;tr class=\"{0}\" &amp;gt;", i % 2 == 0 ? rowStyle : alternateRowStyle);
            }
            else
            {
                result.AppendFormat("&amp;lt;tr &amp;gt;");
            }

            foreach (var prop in propertyArray)
            {
                object value = prop.GetValue(list.ElementAt(i), null);
                result.AppendFormat("&amp;lt;td &amp;gt;{0}&amp;lt;/td &amp;gt;", value ?? String.Empty);
            }
            result.AppendLine("&amp;lt;/tr &amp;gt;");
        }
        result.Append("&amp;lt;/table &amp;gt;");
        return result.ToString();
    }


&lt;/pre&gt;
&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-5328821119794880971?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/K8r4NzseW18IBQ2HhnCmeMwkDgc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/K8r4NzseW18IBQ2HhnCmeMwkDgc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/K8r4NzseW18IBQ2HhnCmeMwkDgc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/K8r4NzseW18IBQ2HhnCmeMwkDgc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/jwXqKk5WR84" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/jwXqKk5WR84/this-extension-method-is-to-convert.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/this-extension-method-is-to-convert.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-7961655737566461455</guid><pubDate>Mon, 30 Jan 2012 17:56:00 +0000</pubDate><atom:updated>2012-01-30T09:56:08.820-08:00</atom:updated><title>Best Extension Methods: Force Download a File</title><description>Below Extension method is for Force Download a file


&lt;pre name="code" class="c#"&gt;
 // full path to your file
    //var yourFilePath = HttpContext.Current.Request.PhysicalApplicationPath + "Files\yourFile.jpg";
    // save downloaded file as (name)
    //var saveFileAs = "yourFile.jpg";

    // start force download of your file
    //Response.ForceDownload(yourFilePath, saveFileAs);    
    public static void ForceDownload(this HttpResponse Response, string fullPathToFile, string outputFileName)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment; filename=" + outputFileName);
        Response.WriteFile(fullPathToFile);
        Response.ContentType = "";
        Response.End();
    }
&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-7961655737566461455?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ukHhOtLvEu9azjSXp5AjjP6yHWg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ukHhOtLvEu9azjSXp5AjjP6yHWg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ukHhOtLvEu9azjSXp5AjjP6yHWg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ukHhOtLvEu9azjSXp5AjjP6yHWg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/CIoSBzUJ0GA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/CIoSBzUJ0GA/best-extension-methods-force-download.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-force-download.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-8400294981234780777</guid><pubDate>Mon, 30 Jan 2012 17:52:00 +0000</pubDate><atom:updated>2012-01-30T09:52:42.631-08:00</atom:updated><title>Best Extension Methods: AddRange To Collection</title><description>Using below extension method we can add a multiple values to a typed collection in one go.

&lt;pre name="code" class="c#"&gt;
 //add value to collection in one statement
    public static void AddRange&lt;T, S&gt;(this ICollection&lt;T&gt; list, params S[] values)
    where S : T
    {
        foreach (S value in values)
            list.Add(value);
    }

&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-8400294981234780777?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/GBxP_X-y7_JZpmlMYgPZNiHS9Ok/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/GBxP_X-y7_JZpmlMYgPZNiHS9Ok/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/GBxP_X-y7_JZpmlMYgPZNiHS9Ok/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/GBxP_X-y7_JZpmlMYgPZNiHS9Ok/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/9CDpasq72fI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/9CDpasq72fI/best-extension-methods-addrange-to.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-addrange-to.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-2720763300742280770</guid><pubDate>Mon, 30 Jan 2012 17:49:00 +0000</pubDate><atom:updated>2012-01-30T09:49:59.548-08:00</atom:updated><title>Best Extension Methods: Is Matching with one of any String</title><description>Using below extension method we can check that a value is matching with one of any parameter or not...


&lt;pre name="code" class="c#"&gt;

    //  below function is replacement for such condition   if(reallyLongStringVariableName == "string1" || 
    //    reallyLongStringVariableName == "string2" || 
    //    reallyLongStringVariableName == "string3")
    //{
    //  // do something....
    //}
    public static bool In&lt;T&gt;(this T source, params T[] list)
    {
        if (null == source) throw new ArgumentNullException("source");
        return list.Contains(source);
    }

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-2720763300742280770?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/sNcObg0RhDXw35_Ho5Gd7rwni9Y/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sNcObg0RhDXw35_Ho5Gd7rwni9Y/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/sNcObg0RhDXw35_Ho5Gd7rwni9Y/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/sNcObg0RhDXw35_Ho5Gd7rwni9Y/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/CgskNdp05WM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/CgskNdp05WM/best-extension-methods-is-matching-with.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-is-matching-with.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-3477533451920238069</guid><pubDate>Mon, 30 Jan 2012 17:45:00 +0000</pubDate><atom:updated>2012-01-30T09:46:11.313-08:00</atom:updated><title>Best Extension Methods: Get Core Type</title><description>Below extension method check for a type and Return underlying type if type is Nullable otherwise return the type

&lt;pre name="code" class="c#"&gt;
 /// &lt;summary&gt;
    /// Return underlying type if type is Nullable otherwise return the type
    /// &lt;/summary&gt;
    public static Type GetCoreType(Type t)
    {
        if (t != null &amp;&amp; IsNullable(t))
        {
            if (!t.IsValueType)
            {
                return t;
            }
            else
            {
                return Nullable.GetUnderlyingType(t);
            }
        }
        else
        {
            return t;
        }
    }

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-3477533451920238069?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/VI3bW6ipltHNWL81oqsq4JQT03o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VI3bW6ipltHNWL81oqsq4JQT03o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/VI3bW6ipltHNWL81oqsq4JQT03o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/VI3bW6ipltHNWL81oqsq4JQT03o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/_llmlR-KLf0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/_llmlR-KLf0/best-extension-methods-get-core-type.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-get-core-type.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-3694934475037606277</guid><pubDate>Mon, 30 Jan 2012 17:43:00 +0000</pubDate><atom:updated>2012-01-30T09:43:49.261-08:00</atom:updated><title>Best Extension Methods: IsNullable</title><description>Below Extension method provides facility to check whether the type is nullable type or not.. 

&lt;pre name="code" class="c#"&gt;

   /// &lt;summary&gt;
    /// Determine of specified type is nullable
    /// &lt;/summary&gt;
    public static bool IsNullable(Type t)
    {
        return !t.IsValueType || (t.IsGenericType &amp;&amp; t.GetGenericTypeDefinition() == typeof(Nullable&lt;&gt;));
    }

&lt;/pre&gt;
&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-3694934475037606277?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/UMJP_2Z9C5689emlzQ1SRoseNPo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UMJP_2Z9C5689emlzQ1SRoseNPo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/UMJP_2Z9C5689emlzQ1SRoseNPo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/UMJP_2Z9C5689emlzQ1SRoseNPo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/eY8cY7TU230" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/eY8cY7TU230/best-extension-methods-isnullable.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-isnullable.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-4887914070669114652</guid><pubDate>Mon, 30 Jan 2012 17:41:00 +0000</pubDate><atom:updated>2012-01-30T09:41:57.902-08:00</atom:updated><title>Best Extension Methods: Convert Generic List To DataTable</title><description>Below extension method converts Generic List to DataTable


&lt;pre name="code" class="c#"&gt;
/// &lt;summary&gt;
    /// Convert a List{T} to a DataTable.
    /// &lt;/summary&gt;
    public static DataTable ToDataTable&lt;T&gt;(this List&lt;T&gt; items)
    {
        var tb = new DataTable(typeof(T).Name);

        PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);

        foreach (PropertyInfo prop in props)
        {
            Type t = GetCoreType(prop.PropertyType);
            tb.Columns.Add(prop.Name, t);
        }

        foreach (T item in items)
        {
            var values = new object[props.Length];

            for (int i = 0; i &lt; props.Length; i++)
            {
                values[i] = props[i].GetValue(item, null);
            }

            tb.Rows.Add(values);
        }

        return tb;
    }

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-4887914070669114652?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/CxrLhK2LIdqPFJ3dwCOP_oUga78/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CxrLhK2LIdqPFJ3dwCOP_oUga78/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/CxrLhK2LIdqPFJ3dwCOP_oUga78/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/CxrLhK2LIdqPFJ3dwCOP_oUga78/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/FbYHifkoijA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/FbYHifkoijA/best-extension-methods-convert-generic.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-convert-generic.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-782845955969078786</guid><pubDate>Mon, 30 Jan 2012 17:39:00 +0000</pubDate><atom:updated>2012-01-30T09:39:28.216-08:00</atom:updated><title>Best Extension Methods: Convert IEnumerable To DataTable</title><description>This extension method converts IEnumerable to DataTable


&lt;pre name="code" class="c#"&gt;

 public static DataTable ToDataTable&lt;T&gt;(this IEnumerable&lt;T&gt; items)
    {
        var tb = new DataTable(typeof(T).Name);
        PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
        foreach (var prop in props)
        {
            //tb.Columns.Add(prop.Name, prop.PropertyType);
            Type t = GetCoreType(prop.PropertyType);
            tb.Columns.Add(prop.Name, t);
        }

        foreach (var item in items)
        {
            var values = new object[props.Length];
            for (var i = 0; i &lt; props.Length; i++)
            {
                values[i] = props[i].GetValue(item, null);
            }

            tb.Rows.Add(values);
        }
        return tb;
    }

&lt;/pre&gt;

&lt;h3&gt; Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-782845955969078786?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/LHAIG0i1mBYa0XTQWfxD_XBOQXk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LHAIG0i1mBYa0XTQWfxD_XBOQXk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/LHAIG0i1mBYa0XTQWfxD_XBOQXk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/LHAIG0i1mBYa0XTQWfxD_XBOQXk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/YCT8UmXN0xI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/YCT8UmXN0xI/best-extension-methods-convert.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-convert.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-8411939191754197795</guid><pubDate>Mon, 30 Jan 2012 17:37:00 +0000</pubDate><atom:updated>2012-01-30T09:37:18.594-08:00</atom:updated><title>Best Extension Methods: Paging on IEnumerables</title><description>Below extension method provides easy way to perform paging on IEnumerables.

&lt;pre name="code" class="c#"&gt;
public static IEnumerable&lt;TSource&gt; Page&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source, int page, int pageSize)
    {
        return source.Skip((page - 1) * pageSize).Take(pageSize);
    }
&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-8411939191754197795?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/fsjV02UK4T-JPjSlpLrhPQrpNhM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fsjV02UK4T-JPjSlpLrhPQrpNhM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/fsjV02UK4T-JPjSlpLrhPQrpNhM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/fsjV02UK4T-JPjSlpLrhPQrpNhM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/8YVFgtNCT2w" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/8YVFgtNCT2w/best-extension-methods-paging-on_30.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-paging-on_30.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5949924287482705652.post-5535248892341884321</guid><pubDate>Mon, 30 Jan 2012 17:33:00 +0000</pubDate><atom:updated>2012-01-30T09:33:45.830-08:00</atom:updated><title>Best Extension Methods: Paging on IQueryable</title><description>Below extension methods allow easy way to perform paging on IQueryables.

&lt;pre name="code" class="c#"&gt;

public static IQueryable&lt;TSource&gt; Page&lt;TSource&gt;(this IQueryable&lt;TSource&gt; source, int page, int pageSize)
    {
        return source.Skip((page - 1) * pageSize).Take(pageSize);
    }

&lt;/pre&gt;

&lt;h3&gt;Compiled By: Rajesh Rolen&lt;/h3&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5949924287482705652-5535248892341884321?l=dotnetacademy.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8-ciUAgYl_crz2CtYTbfwONiwfE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8-ciUAgYl_crz2CtYTbfwONiwfE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8-ciUAgYl_crz2CtYTbfwONiwfE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8-ciUAgYl_crz2CtYTbfwONiwfE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/FJUvB/~4/xXGu0azHjpU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/blogspot/FJUvB/~3/xXGu0azHjpU/best-extension-methods-paging-on.html</link><author>noreply@blogger.com (Rajesh Rolen)</author><thr:total>0</thr:total><feedburner:origLink>http://dotnetacademy.blogspot.com/2012/01/best-extension-methods-paging-on.html</feedburner:origLink></item></channel></rss>

