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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:44:11+00:00 2026-05-12T11:44:11+00:00

There’s one specific feature that I wish was in the .NET framework, but isn’t.

  • 0

There’s one specific feature that I wish was in the .NET framework, but isn’t. I wish there were a DBDataReader.GetString (or GetDateTime, GetInt32, etc.) overload that accepted the field name instead of the index. Using the field name makes for easier maintenance IMO, but the GetXxx methods only accept the field position.

I can add these to my project (at least in a limited capacity to suit my immediate needs) by using extension methods, but something about that feels wrong. Beyond the obvious problem that I’d have to repeat this process for every new project, is there any reason not to do what I’m thinking about?

For example, am I headed down a slippery slope of trying to rewrite the framework to suit my whims? Will I leave the poor guy who has to modify my code (probably me) scratching his head trying to figure out what’s going on? Am I violating some core principle of OOP?

Just looking for guidance and viewpoints. Thanks.

  • 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-05-12T11:44:11+00:00Added an answer on May 12, 2026 at 11:44 am

    This is exactly one of the scenarios extension methods are able to solve. You need functionality that isn’t already available on a type over which you have no control.

    As far as duplicating the code in each of your projects, what you need to do is create a class library project to store your common/shared code like this and then either include that project in each Solution and use project references or compile the project, put the resulting assembly in a shared location and include it as a file project reference.

    Remeber that extension methods are only available when they are “brought in to scope”. This means that if you have an extension method defined as:

    namespace CustomExtensions
    {
        public static class StringExtensions
        {
           public static string InvariantToString(this int value)
           {
              return value.ToString(System.Globalization.CultureInfo.InvariantCulture);
           }
        }
    }
    

    It will not be visible on any string values unless the code file includes the CustomExtensions namespace with a using directive.

    For this reason, it is recommended that you do not put your own extensions in a .NET Framework defined namespace but rather use your own namespace. Doing that minimizes the potential for confusion because your extension won’t be available unless it is explicitly brought in to scope.

    Also, keep in mind that if you provide an extension method with the exact same signature as a “built-in” method, your extension method will never be visible or callable – the built-in method always takes precedence. If Microsoft decides to include that functionality in a later version of the Framework and uses the exact same signature you chose then your extension method will no longer be called.

    When you define an extension method you aren’t actually redefining the underlying type being extended so you don’t have your own “individual versions”. All an extension method provides is a convenient and more natural way to call a static method in a static class. In fact, using my example extension method above, these are equivalent calls:

    int i = 42;
    Console.WriteLine(i.InvariantToString());
    Console.WriteLine(StringExtensions.InvariantToString(i));
    

    While Microsoft does put a lot of thought in to what to include or not include in the Framework, they have no way of knowing about specific use-cases that might be driving your particular need for certain functionality. Yes, most of the time they do a great job and provide functionality “out of the box” but other times they don’t. (A good example is missing an InvariantToString() method.)

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

Sidebar

Related Questions

There is one method in Lookup<,> that is not in ILookup<,> : public IEnumerable<TResult>
There is a conversion process that is needed when migrating Visual Studio 2005 web
There is a field in my company's Contacts table. In that table, there is
There is no problem to get the src or alt separately,but how can get
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There is previous little on the google on this subject other than people asking
There seem to be many ways to define singletons in Python. Is there a
There are a few ways to get class-like behavior in javascript, the most common
There are numerous Agile software development methods. Which ones have you used in practice

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.