Parameterized type casting?

T

Tomer

Hi,
Few questions:

1.How can I change during run time the type casting I'm performing on an
object?

for example, something like this:

Type controllerType = Type.GetType("controllerTest");

return (controllerType)controller;

where controller is the type of the base class
and controllerType changes during runtime.
controllerTest is the class name of the class the inherits from the base
class.


2.How can I create a new form which is based on an existing form that I have
created?

for example:
I have a base form that have two buttons OK and Cancel.
I want to create a new form that inherits from that form, so that the new
form will have those two buttons from the start.



Thanks in advanced!!

Tomer.
 
A

Alex Feinman [MVP]

You cannot change the object type by using typecasting. Runtime type is an
immutable object property. If your type implements IConvertible, it might be
converted to various types, but not cast. Casting is a logical operation.
E.g.
return (Control) new ComboBox();
This returns an instance of ComboBox even though it is cast to Control
 
T

Tomer

Hi Alex,

Thanks for the quick reply!

Have you any idea about the second issue?

Tomer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top