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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:23:33+00:00 2026-06-14T14:23:33+00:00

How do I append string to a type name then pass it as another

  • 0

How do I append string to a type name then pass it as another type? Here is an example:

 public T Get<T>(int id)
        {
           return dbAccess.Get<T>(id);
        }

If I call this method like

SomeObject.Get<Class1>(1234);

I would like to change Class1 to be Class1Data by appending the string “Data” to any passed class, so the dbAccess.Get method would take the object as Class1Data as a conversion of Class1.

  • 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-14T14:23:34+00:00Added an answer on June 14, 2026 at 2:23 pm

    Something like this would work:

    public T Get<T>(int id)
        {
            var newTypeName = typeof(T).FullName + "Data";
            var newType = Type.GetType(newTypeName);
            var argTypes = new [] { newType };
            var method = GetType().GetMethod("Get");
            var typedMethod = method.MakeGenericMethod(argTypes);
            return (T) typedMethod.Invoke(this, new object[] { id });
        }
    

    In case your XxxData object don’t inherit from Xxx, you may want to do some automapping before returning the result.

    Then you would have to replace the last line to:

            var dataResult = typedMethod.Invoke(this, new object[] { id });
            var result = new T(); // You will have to add a new() constraint on generic parameter
            // Map your dataResult object's values onto the result object's values
            return result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public struct Parameter { public Parameter(string name, string type, string parenttype) { this.Name =
how to append the value of string in between NSString? for example: NSString* str1
I have web service which return json string like : d={main0ID:abc.es/main,main1ID:ah/main} I wanna append
I have the following code : std::string Utils::get() { std::string result; result.append(1, 'x'); result.append(1,
I'm trying to append a string of svg elements to the dom. This is
I have a certain boost::filesystem::path in hand and I'd like to append a string
I have a file full of ascii data. How would I append a string
I have an element: <select id=row /> I want to append a string to
I have a VB method Public Sub append_text(ByVal s As String) f1.TextBox1.AppendText(s) End Sub
I am trying to append date to the file name before copying in PHP.

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.