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 / February 2005

Tip: Looking for answers? Try searching our database.

Deriving from the Process class.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yitz - 08 Feb 2005 08:47 GMT
I would like to associate an object derived from the
System.Diagnostics.Process class with an existing process.
Something like this:

public class MyProcess : System.Diagnostics.Process
{
}
MyProcess p = MyProcess.GetProcessById(processID) ; // NOT VALID

The assignment however is not valid since the GetProcessById() method
returns a (base) Process object which cannot be assigned to a (derived)
MyProcess object. Is there any way to associate the derived class
object with an existing process?
cody - 08 Feb 2005 09:52 GMT
What you want is covariant return types that is overridden methods can
return subclasses from the original return type but this is not supported in
C# yet but I really hope it will in the future.

> I would like to associate an object derived from the
> System.Diagnostics.Process class with an existing process.
[quoted text clipped - 9 lines]
> MyProcess object. Is there any way to associate the derived class
> object with an existing process?
Fabian Schmied - 09 Feb 2005 09:19 GMT
> What you want is covariant return types that is overridden methods can
> return subclasses from the original return type but this is not  
> supported in
> C# yet but I really hope it will in the future.

That wouldn't change anything. GetProcessById is a static method  
implemented by the Process class and it always creates a Process object.  
With or without covariant return types, you cannot transform this into a  
MyProcess object.

The best I can think of would be to wrap the Process instance in you  
MyProcess object, i.e.

MyProcess p = new MyProcess(Process.GetProcessById(processID));

Fabian
cody - 09 Feb 2005 11:59 GMT
> > What you want is covariant return types that is overridden methods can
> > return subclasses from the original return type but this is not
[quoted text clipped - 10 lines]
>
> MyProcess p = new MyProcess(Process.GetProcessById(processID));

Oh I misunderstood, yes in case of a static method covariance won't help but
you can define a new method with the same name as the inherited class

public static new MyProcess GetProcessById(int pid)
{
   return new MyProcess (Process.GetProcessById(pid));
}

Rate this thread:







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.