O
ozbear
The System.Diagnostics namespace contains a Process class
which defines a static method GetProcesses. GetProcesses
returns an array of Process instances of all processes running
running on the PC (or another PC).
I wish to subclass Process to include an additional property.
My problem is with the GetProcesses method. Since its return
value is a Process[], I cannot just downcast a Process element
to MyProcess to access the my property as well as the ones
the Process already defines.
Since the fetching of all processes occurs frequently, and the
list can be long, I would prefer to not loop thru the Process[]
array and clone or otherwise construct a MyProcess from a
Process element to arrive at a correponding MyProcess[] array.
I have resorted to defining an extension method to the Process
class rather than subclassing it to provide my additional
information, but get the impression that extension methods
are frowned upon when inheritance could/should be used instead.
Is there an alternative to using an extension method to
extend a class which has a static method that returns an
array of class instances in a general way?
Oz
which defines a static method GetProcesses. GetProcesses
returns an array of Process instances of all processes running
running on the PC (or another PC).
I wish to subclass Process to include an additional property.
My problem is with the GetProcesses method. Since its return
value is a Process[], I cannot just downcast a Process element
to MyProcess to access the my property as well as the ones
the Process already defines.
Since the fetching of all processes occurs frequently, and the
list can be long, I would prefer to not loop thru the Process[]
array and clone or otherwise construct a MyProcess from a
Process element to arrive at a correponding MyProcess[] array.
I have resorted to defining an extension method to the Process
class rather than subclassing it to provide my additional
information, but get the impression that extension methods
are frowned upon when inheritance could/should be used instead.
Is there an alternative to using an extension method to
extend a class which has a static method that returns an
array of class instances in a general way?
Oz