PC Review


Reply
Thread Tools Rate Thread

Parameterized type casting?

 
 
Tomer
Guest
Posts: n/a
 
      29th Dec 2004
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.


 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      29th Dec 2004
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

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Tomer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Tomer
Guest
Posts: n/a
 
      29th Dec 2004
Hi Alex,

Thanks for the quick reply!

Have you any idea about the second issue?

Tomer.



"Alex Feinman [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
> "Tomer" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.
> >
> >

>
>



 
Reply With Quote
 
Daniel Moth
Guest
Posts: n/a
 
      29th Dec 2004
Aren't you answering your own question with the second issue? Use Form
inheritance; the designer part will not work but it does at runtime. This
(inc. workarounds) has been discussed many times before:
http://groups-beta.google.com/group/...d803b00bd8cdec

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Tomer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Alex,
>
> Thanks for the quick reply!
>
> Have you any idea about the second issue?
>
> Tomer.
>
>
>
> "Alex Feinman [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>>
>> --
>> Alex Feinman
>> ---
>> Visit http://www.opennetcf.org
>> "Tomer" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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.
>> >
>> >

>>
>>

>
>



 
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
Forgot Syntax: calling a parameterized constructor of the same class from a non-parameterized one Sathyaish Microsoft C# .NET 5 5th Apr 2007 03:25 PM
Type Casting pitdog@gmail.com Microsoft C# .NET 1 2nd Jun 2006 07:11 PM
Can a method be declared with a parameterized return type? Brad Wood Microsoft C# .NET 5 2nd Dec 2005 05:03 PM
casting to type Ron Vecchi Microsoft ASP .NET 3 3rd Mar 2004 05:23 PM
Type casting object type to user defined class or interface Programmer Microsoft C# .NET 6 17th Jan 2004 09:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:54 PM.