How to Create Generic Get Custom WebConfig Section Extension Method
<p>i have the following Code to get a  Custom Webconfig Section</p>

<pre><code>Configuration config = WebConfigurationManager.OpenWebConfiguration
(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + "/ExternalConfig");
        Sample1Section myHandler =
            (Sample1Section)config.GetSection("settings");
</code></pre>

<p>i want to convert it into Generic Extension Method so i wont repeat this same code for every Custom Section i create.</p>

<p><strong>Update 1</strong>: I get Compile Time Error "Static Class cant have non-static Method"</p>

<pre><code>public static class MyExtensions
{
    public T GetSection&lt;T&gt;(this string sectionName) where T : class
    {
        Configuration config = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath + "/ExternalConfig");
        return config.GetSection(sectionName) as T;
    }
}
</code></pre>

<p><strong>Update 2</strong>: Fixed thanks to BrandonZeider :)</p>

<pre><code>   public static class MyExtensions
{
    public static T GetSection&lt;T&gt;(this string sectionName) where T : class
    {
        Configuration config = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath + "/ExternalConfig");
        return config.GetSection(sectionName) as T;
    }
}
</code></pre>

<p>thanks In Advanced.</p>
