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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:24:34+00:00 2026-05-31T02:24:34+00:00

Is it possible to change TEntity to NewEntity after SomeClass has been instantiated? For

  • 0

Is it possible to change TEntity to NewEntity after SomeClass has been instantiated?

For example, take this class definition:

public class SomeClass<TEntity> where TEntity : class
{
   public void ChangeSet<NewEntity>()
    {
        TEntity = NewEntity;//not valid
    }
 }

Instantiated for example like this:

var sc = new SomeClass<SomeEntity>();

How can I accomplish this?

sc.ChangeSet<NewEntity>();
  • 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-31T02:24:36+00:00Added an answer on May 31, 2026 at 2:24 am

    Is it possible to change TEntity to NewEntity after SomeClass has been instantiated?

    No, this is not possible. How would the CLR know how to map the values from TEntity to SomeEntity? They are different types. It would be like asking your grocer to turn an apple into an orange.

    The code below is not recommended. There are so many problems you would have to worry about, and it would be prone to bugs. I am providing it as an example of what you are asking the CLR to do.

    SomeClass<Foo> fooClass = new SomeClass<Foo>():
    //do stuff to fooClass
    SomeClass<Baz> = fooClass.ChangeSet<Baz>();
    
    public class SomeClass<T> where T : class
    {
        public SomeClass<K> ChangeSet<K>() where K:class
        {
           var changed = new SomeClass<K>();
           //manually map the properties over
           //but how do you know that Foo.PropertyA fits into Baz.PropetyZed?
           //what happens if Foo.A has a string length of 100, but Baz.A has a max length of 50? What do you do?
           //What id Foo.ID is an INT and Baz.ID is a GUID?
           return changed;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is possible change background-color on same td in fullcalendar? for example: I like have
Possible Duplicate: Change single variable value in querystring I'm retrieving the current URL: http://example.com/?s=original&fq=category
Possible Duplicate: Change an element's CSS class with JavaScript I'm trying to set div's
Is it possible to change an items class or ID based on some type
Is it possible to change the style of a class via JavaScript without looping
Is it possible to change the font from the <pre> tag? For example, I
Question: Is it possible to (automatically) change the base class of auto-generated domain objects
Possible Duplicate: Change color of selection How does this site manage to make text
Possible Duplicate: Change CSS Dynamically I need to change the height of a div
Is it possible to change the width of a scroll bar on a form.

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.