Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7771443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:39:15+00:00 2026-06-01T16:39:15+00:00

We use a utility that generates code. I’d like to extend it and thought

  • 0

We use a utility that generates code. I’d like to extend it and thought I might be able to do it without going back to the code generator. here is the problem.

The code generator gives me:

public abstract class BaseService
{
    protected virtual SqlCommand CreateSelectCommand(string whereClause, Hashtable parameters, string orderClause, int maxRows);
    protected DataSet Fill(SqlCommand command);
}

Then it generates lots of classes that implement this class. e.g.

public class ChildService : BaseService
{
    protected override SqlCommand CreateSelectCommand(string whereClause, Hashtable parameters, string orderClause, int maxRows)
    {
        //implementation here
    }

    protected override SqlCommand CreateSelectCommand(string whereClause, Hashtable parameters, string orderClause, int maxRows)
    {
        //implementation here
    }

    public virtual DataSet Select(string whereClause, System.Collections.Hashtable parameters, string orderClause, int maxRows)
    {
        SqlCommand command = CreateSelectCommand(whereClause, parameters, orderClause, maxRows);
        return Fill(command);
    }
}

Now I want to extend all the child classes to give me an override of the Select method. I tried an extension method something like this:

public DataSet Select(this BaseService service, string whereClause, Hashtable parameters, string orderBy, int startRowIndex, int maximumRows)
{
        SqlCommand command = service.CreateSelectCommand(whereClause, parameters, orderClause, maxRows);
        //Modify the command here
        return service.Fill(command);
}

But the compiler complains because the service parameter is not an instance of the child class and so cannot access the protected CreateSelectCommand and Fill methods.
Is there any way around this so that I don’t have to implement this in every child class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:39:17+00:00Added an answer on June 1, 2026 at 4:39 pm

    Is there any way around this so that I don’t have to implement this in every child class?

    No, there isn’t.

    Extension methods are static methods on static classes that only appear (through the magic of intellisense) to “belong” to a type. This means that types need to match exactly (for one).

    It also means that they do not belong to the type and don’t have access to any protected/private members declared in the type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

any easy to use utility/tool/profiler/benchmark that able to test what is the maximum users
Is it possible to extend the SubSonic generator without modifying it's code? I would
I have a WinForms utility that I use constantly, and enhance regularly. Roughly one
We use this small utility method. But we don't like it. Since it's not
I need a little utility function that generates a checksum from an array of
I am using Xcode 3.2.3 When i am insist to use utility function for
How to use TKPROF utility along with syntax and parameters?
I want to use the FileMerge utility on my mac, but it isn't installed.
I use an asp (classic) utility file to create json objects from an SQL
I'm trying to use the MiscUtil.Conversion utility in Silverlight. http://www.yoda.arachsys.com/csharp/miscutil/ When I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.