Solved

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

Posted on 2012-03-13
1
2,438 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
1 Comment
 
LVL 74

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 37
visual Basic Net vs c# net 8 54
Problem to page 4 23
Events in static methods 3 24
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now