473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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.

Aug 16 '07 #1
1 1132
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.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"not_a_commie" <no********@gmail.comwrote in message
news:11**********************@g12g2000prg.googlegr oups.com...
>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.

Aug 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
14
by: J. Makela | last post by:
Hallo. This should be a pretty entertaining question for you *real* javascript writers.. I, being the lowly photoshop guy at an ad agency made the mistake of actually saying "HTML" in a...
2
by: GM | last post by:
Hi, I have 2 objects A and B. I want to copy only the values of B across to A without changing the reference of A. Is there a way to achieve this without the use of reflection? Cheers, ...
7
by: Richard Forester | last post by:
Hello. I need some help understanding what goes on when an array is copied. I create 2 arrays and copy one to the other: int pins = {9, 3, 7, 2}; int copy = new int; for (int i = 0; i !=...
5
by: lion | last post by:
in .net, if you set annstance-A of a class equal to another instance-B, a pointer will add to B, but if i want to create a copy of B instead of pointer, how to operate? Note:serialization...
8
by: downwitch | last post by:
Either I don't understand (entirely possible), or there's no way to copy parts of a class hierarchy from one instance to another. Say I have a class called Foo, and it contains, among other...
4
by: andychambers2002 | last post by:
I'm working on a "TempFile" class that stores the data in memory until it gets larger than a specified threshold (as per PEP 42). Whilst trying to implement it, I've come across some strange...
7
by: pallav | last post by:
I'm having some trouble with my copy constructor. I've tried using gdb to find the bug, but it seg faults in the destructor. I'm not able to see what I'm doing wrong. Since I'm using pointers, I...
7
by: Jeffrey Barish | last post by:
(Pdb) myclass MyClass( 0, 0, 'A string', 123.45) (Pdb) copy.copy(myclass) *** TypeError: TypeError('__new__() takes at least 4 arguments (2 given)',) I see 4 arguments (actually, 5 because...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.