PC Review


Reply
Thread Tools Rate Thread

Copying a derived type to another type that inherits from derived type Options

 
 
Bob Jones
Guest
Posts: n/a
 
      29th Jun 2007
Ok, I am curious if this can be done in C# 2.0 via some internal .net
functionality or if I have to do a coversion myself such as a copy
construtor or override the explicit operator.

I have 3 classes.


ClassA
ClassB which derives from ClassA
ClassC which derives from ClassA as well


I can implicitly convert to ClassA from ClassB and ClassC. Easy
enough


I would like to convert ClassB to ClassA and then create a new
instance of ClassC and use the converted ClassA to fill in the
derived
methods and properties in ClassC without having to write code that
literally copies values from one class to the other. Is this
possible?


Psuedo Code:


ClassB classb = new ClassB();
ClassC classc = (ClassC)(ClassA)classb; //this doesn't work but you
get the point.


Thanks!!

 
Reply With Quote
 
 
 
 
Bob Jones
Guest
Posts: n/a
 
      29th Jun 2007
On Jun 29, 5:21 pm, Bob Jones <goodold...@gmail.com> wrote:
> Ok, I am curious if this can be done in C# 2.0 via some internal .net
> functionality or if I have to do a coversion myself such as a copy
> construtor or override the explicit operator.
>
> I have 3 classes.
>
> ClassA
> ClassB which derives from ClassA
> ClassC which derives from ClassA as well
>
> I can implicitly convert to ClassA from ClassB and ClassC. Easy
> enough
>
> I would like to convert ClassB to ClassA and then create a new
> instance of ClassC and use the converted ClassA to fill in the
> derived
> methods and properties in ClassC without having to write code that
> literally copies values from one class to the other. Is this
> possible?
>
> Psuedo Code:
>
> ClassB classb = new ClassB();
> ClassC classc = (ClassC)(ClassA)classb; //this doesn't work but you
> get the point.
>
> Thanks!!



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delegate Return Type is Derived Type James.R.Thigpen@gmail.com Microsoft VB .NET 11 29th Feb 2008 06:02 PM
Copying a derived type to another type that inherits from derived type Bob Jones Microsoft C# .NET 3 2nd Jul 2007 02:47 PM
Interface & Derived Return Type hufaunder@yahoo.com Microsoft C# .NET 9 23rd Apr 2007 08:13 AM
Change return type in derived function =?Utf-8?B?RGF2ZSBCb29rZXI=?= Microsoft C# .NET 1 15th Dec 2005 05:20 PM
TypeLoadException when dynamically creating a derived generic type Wolfgang Portugaller Microsoft Dot NET Framework 0 9th Sep 2005 10:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:54 AM.