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

  • SEARCH
  • Home
  • 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 8194685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:54:22+00:00 2026-06-07T04:54:22+00:00

I have an API which includes some methods that take in a type parameter.

  • 0

I have an API which includes some methods that take in a type parameter. I am now converting them to generic methods as part of improving the API (more type-safe), while keeping the non-generic version around for backward compatibility.

Current – to be obsoleted:

public object MyMethod(object value, Type expectedType)

New:

public T MyMethod<T>(object value)

However, Mymethod calls a private helper method which also takes in a type parameter:

private object HelperMethod(object value, Type expectedType)

Question: should I also make this private helper method generic?

I have my own answer below, but I would like to know if I’m missing something. I appreciate your insights very much.

My answer is no, I should not make this private method generic.

Reason 1: this helper method is private, so even if I made it generic, it doesn’t improve the API.

Reason 2: If I make it generic, then the non-generic public methods will have to use reflection to pass the type parameter to this generic method, which means more overhead.

  • 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-07T04:54:24+00:00Added an answer on June 7, 2026 at 4:54 am

    Making your private helper method generic does improve the API by carrying the generic type-specificity all the way through your implementation. Your implementation isn’t fully realizing the type safety benefits of generics if you throttle the type down to a core that juggles typeless System.Objects around.

    For example, why is the parameter to MyMethod still a System.Object? If that parameter originates in source, chances are good that it should be a type parameter too. If the parameter originates in data, you’re probably better off with System.Object. Generics are most useful when they are used with source code, because source code expressions implicitly provide the type in most contexts.

    The hidden costs of generics depends on the mix of types that will be used with the API. If most of the types will be value types (built-ins and structs), then switching the API to generics could raise your memory consumption because the generic code must be jit’d differently for each value type. If the majority of types used with your generic API are reference types (classes and interfaces), code/memory explosion isn’t a concern because all reference types share the same JIT’d code.

    Whether the cost of having the old API call the new generic API is a) measurable and b) acceptable depends entirely upon what you’re doing in your private helper method – in particular, what the private helper method does with the Type parameter.

    If the helper method implementation is fairly lightweight and you determine (by performance measurements) that the cost of adapting the old API to call the new generic helper is unacceptable, I would consider duplicating the helper method implementation, side by side, one in the old style and one in the new generic style. This eliminates crossover conversion costs between the API styles and eliminates the risk of introducing new bugs into the old API, at the cost of slightly increased internal code maintenance efforts.

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

Sidebar

Related Questions

I have a REST api which dumps some json data (user info, etc). Now
I have the win32 API CommandLineToArgvW which returns a LPWSTR* and warns me that
I have an API in NETMF C# that I am writing that includes a
so i have made some java files which provide some specific API functionality. I
I have some custom validation code, which includes a $formatter. (I store currency in
I have a scenario in which I have REST API which manages a Resource
I have a web site with an API which publishes the information using JSON.
I have to deal with an API which need to be provided a DataSource
I have a domain foo.com on server bar. I have a subdomain api.foo.com which
I have an iPhone application which basically is getting information from an API (in

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.