Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / December 2004

Tip: Looking for answers? Try searching our database.

How to replace a object in place?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lei Jiang - 28 Nov 2004 11:43 GMT
For example :

class A
{
   int a;
}

class B : A
{
   int b;
}

There are a lot of instance of A in a system(this means there are a lot of
reference to A), and I want to replace all A with B at runtime and make all
references originally point to A now point to B.

These problem can be stated in another way : how to create object B at the
memory address of A?
Mattias Sj?gren - 28 Nov 2004 19:10 GMT
>These problem can be stated in another way : how to create object B at the
>memory address of A?

You can't.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Heath Stewart [MSFT] - 29 Nov 2004 08:01 GMT
I'm not sure what you're trying to accomplish, but if you require that
you can do this often in your code you might consider a level of
indirection. That is, your objects that currently reference A (and you
want to reference B, which is possible since B derives from A) then they
should reference X, where X references A (or B). Class X would not be in
the inheritence chain derived from A. This would allow you to change
what X references while all the objects referencing X should get their
reference to the A base class from X.

This is similar to System.WeakReference, except that it serves a
different purpose in a similar manner.

Signature

Heath Stewart
Software Design Engineer
Developer Division Sustained Engineering
Microsoft Corporation

Lei Jiang - 03 Dec 2004 01:53 GMT
Thanks! In fact it's a design problem.

> I'm not sure what you're trying to accomplish, but if you require that
> you can do this often in your code you might consider a level of
[quoted text clipped - 7 lines]
> This is similar to System.WeakReference, except that it serves a
> different purpose in a similar manner.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.