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 8258453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:32:28+00:00 2026-06-08T02:32:28+00:00

Note: My code happens to be in C#, but I don’t think that’s significant

  • 0

Note: My code happens to be in C#, but I don’t think that’s significant to solving the problem.

Problem

I’m trying to reduce code duplication in two old classes we have that are both used for loading queries from XML. They both have constructors that take the XML location, both have Execute methods that accept a collection of SQL parameters and both provide various static overloaded methods to make it quick and easy to run a query with maybe a single named paramater, or no parameter, or one with a non-default SQL connection object. These static methods also accept the XML location as the parameter, and internally they’re calling the constructor, and so on, and finally just returning the first DataTable of the DataSet.

public static DataTable GetQuery(string queryName) { ... }
public static DataTable GetQuery(string queryName, string parameterName, string parameterValue) { ... }
public static DataTable GetQuery(string queryName, Hashtable parameters) { ... }
public static DataTable GetQuery(string queryName, Hashtable parameters, IConnection connection) { ... }

and so on.

The difference between the two is that one looks for the XML file in the filesystem, and the other looks for them embedded in the assembly.

Possible Solution 1

I was thinking of unifying them into one that can do either, using different implementations of a separate IQuerySource interface, passed into the constructor, or something. But this would mean either the constructor would have to always be called ahead of time, or the GetQuery methods would need to be passed the IQuerySource object every time, as well. I’m trying to avoid things like that, because these GetQuery methods are used everywhere in the client code, for quick little things like GetQuery("GetUserDetails","UserID",userId.ToString()).

Possible Solution 2

Alternatively, I could create two very light classes, FileQuery and DllQuery, that would sit on top of the unified class, and they would always pass FileQuerySource and DllQuerySource down to the constructor and/or GetQuery methods. This would keep the client code small, but I don’t want to have maintain (marginally thinner) versions of all the existing GetQuery overloads in two more places, in addition to the core class!

Possible Solution 3

Another alternative would be like the above, but exposing the unified class so you could call, say, DllQuery.Q.GetQuery("GetUserDetails","UserID",userId.ToString()), but then I’m not sure how DllQuery can intercept the call and make sure the Q instance of the unified class always gets the right source for the job.

An additional complexity is that to get XML from an assembly, we’re currently using System.Reflection.Assembly.GetCallingAssembly(), so wherever that’s called has to sit directly under the surface of the client code, otherwise we’ll get our Data assembly instead of the client assembly.

I understand this question might be a bit subjective, but I’m hoping there’s some well-understood and well-defined design pattern, or something, for addressing this.

  • 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-08T02:32:29+00:00Added an answer on June 8, 2026 at 2:32 am

    I think this is quite influenced by opinion, but I’d do this:

    public interface IQuerySource
    {
      // function GetXML(Assembly caller)
    };
    
    public class XmlQuery
    {
      XmlQuery(IQuerySource source);
      // GetQuery functions
    }
    
    public class FileQuery : IQuerySource
    {
      private FileQuery() {} // Only accessable through the Q property
      public static readonly XmlQuery Q = new XmlQuery(new FileQuery());
    
      // function GetXML(Assembly caller) for a file source
    }
    
    public class DllQuery : IQuerySource
    {
      private DllQuery() {} // Only accessable through the Q property
      public static readonly XmlQuery Q = new XmlQuery(new DllQuery());
    
      // function GetXML(Assembly caller) for an assembly source
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note my code below. I am trying to figure out why my data is
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
Note that all the code is a simplified example in order to only communicate
Note: I'm using Mercurial as an example here, because that's what I'm trying to
I think that it is a very basic question, but I have spent hours
Note: This code actually codes from a tutorial book I'm reading at the moment,
Here is the code: //Note: x actually isn't defined, I'm pulling it from an
I have the following HTML code (note no closing tags on <\option> ) generated
System.Diagnostics.Contracts.ContractException is not accessible in my test project. Note this code is purely myself
let's say I have a html structure like this -> (note: in my code

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.