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>();
No, this is not possible. How would the CLR know how to map the values from
TEntitytoSomeEntity? 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.