possible to copy Type instance to Type instance wo/ changing ref?

N

not_a_commie

I was wondering if it was possible to copy a type such that you don't
actually change the reference of the object you're copying into. I
understand that you would usually use the ref keyword for this
situation, but my (legacy) code is in such a situation that this is
impossible.

The unworking function that I need to make work:

void changeType(Type b){
b = Type.GetType(myType); // changed ref on b
}

what I want:
void changeType(Type b){
b.ChangeTo(myType);
}

I have the same situation elsewhere with strings. I need a string
function like "ChangeTo" that just changes the pointer to the string
table without changing the reference like the "=" operator does.
 
N

Nicholas Paldino [.NET/C# MVP]

Nope, you can't do that. You are going to have to change the signature
to be a ref parameter and then change the call sites accordingly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top