Solved

Extension method must be defined in a non-generic static class

Posted on 2012-03-13
1
2,617 Views
Last Modified: 2012-03-13
how can we fix this error ?

namespace truliaxml
{
     

public partial class Default : System.Web.UI.Page
    {

   

        protected void Page_Load(object sender, EventArgs e)
        {



.....code...

call SplitWithQualifier(...)
}

  public static string[] SplitWithQualifier(this string text,
                                                char delimiter,
                                                char qualifier,
                                                bool stripQualifierFromResult)
        {
            string pattern = string.Format(
                @"{0}(?=(?:[^{1}]*{1}[^{1}]*{1})*(?![^{1}]*{1}))",
                Regex.Escape(delimiter.ToString()),
                Regex.Escape(qualifier.ToString())
            );

            string[] split = Regex.Split(text, pattern);

            if (stripQualifierFromResult)
                return split.Select(s => s.Trim().Trim(qualifier)).ToArray();
            else
                return split;
        }

}


}
0
Comment
Question by:goodluck11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37717937
Just as the error implies:  put your extension into a static class. For example:

public static class MyExtensions
{
public static string[] SplitWithQualifier(this string text,
                                                char delimiter,
                                                char qualifier,
                                                bool stripQualifierFromResult)
        {
            string pattern = string.Format(
                @"{0}(?=(?:[^{1}]*{1}[^{1}]*{1})*(?![^{1}]*{1}))",
                Regex.Escape(delimiter.ToString()),
                Regex.Escape(qualifier.ToString())
            );

            string[] split = Regex.Split(text, pattern);

            if (stripQualifierFromResult)
                return split.Select(s => s.Trim().Trim(qualifier)).ToArray();
            else
                return split;
        }
}

Open in new window


As long as you have the namespace containing this new class imported (i.e. brought in via a using statement), then you will be able to use the extension method.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I bind a WPF ComboBox to an ItemSource using XAML? 2 30
Name Space error VS2015 1 35
Selenium and Xpath 4 29
CSS for Popup in ASP.NET 4 15
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question