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
Solved

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

Posted on 2012-03-13
1
2,582 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sort GridView by ID Descending 1 17
defining NULL or 0 10 44
How to use NFS (Network File System) in Asp.net mvc 5? 4 44
need to convert function to c# 5 30
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 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