By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,361 Members | 1,799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,361 IT Pros & Developers. It's quick & easy.

inherit form and generics

P: n/a
Hi. I want to create a base form class with a generic parameter.

public BaseForm<T: Form
{}

public MyForm : BaseForm<MyType>
{}

The problem here is that the inherited form doesn't work in the visual
studio designer but the execution is perfect. Without the generic
parameter it works in the designer.

Is there a way to this or, does anyone has a better solution?

Thank you

Cassio Tavares

Jun 26 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
the designer has to be able to instanciate the form itself for it to work in
the designer... if it cant do this, the form wont load

"CassioT" <ca*****@gmail.comwrote in message
news:11**********************@q69g2000hsb.googlegr oups.com...
Hi. I want to create a base form class with a generic parameter.

public BaseForm<T: Form
{}

public MyForm : BaseForm<MyType>
{}

The problem here is that the inherited form doesn't work in the visual
studio designer but the execution is perfect. Without the generic
parameter it works in the designer.

Is there a way to this or, does anyone has a better solution?

Thank you

Cassio Tavares

Jun 26 '07 #2

P: n/a

So, I think the designer doesn't know what to pass in the generic
parameter.

I have a temporary solution but I don't like it. When I have to use
the designer,
I change the inheritance to System.Windows.Forms.Form. Is not a good
solution
because I can't add a grid to the base form and design it in the
inherited.
On 26 jun, 17:39, "Smokey Grindle" <nos...@nospam.comwrote:
the designer has to be able to instanciate the form itself for it to work in
the designer... if it cant do this, the form wont load

"CassioT" <cass...@gmail.comwrote in message

news:11**********************@q69g2000hsb.googlegr oups.com...
Hi. I want to create a base form class with a generic parameter.
public BaseForm<T: Form
{}
public MyForm : BaseForm<MyType>
{}
The problem here is that the inherited form doesn't work in the visual
studio designer but the execution is perfect. Without the generic
parameter it works in the designer.
Is there a way to this or, does anyone has a better solution?
Thank you
Cassio Tavares

Jun 26 '07 #3

P: n/a
On Tue, 26 Jun 2007 14:12:47 -0700, CassioT <ca*****@gmail.comwrote:
On 26 jun, 17:39, "Smokey Grindle" <nos...@nospam.comwrote:
>>
the designer has to be able to instanciate the form itself for it to
work in
the designer... if it cant do this, the form wont load

So, I think the designer doesn't know what to pass in the generic
parameter.
What generic parameter? You specify the generic parameter in your class
declaration. As long as you're trying to instantiate the derived type
rather than the generic type, I don't see how that's an issue.

Do you have a parameterless constructor for your derived type?

I understand the need for the designer to be able to instantiate the
object, but if you have a parameterless constructor, I would think that
would be sufficient. If you do and it still doesn't work, I don't have an
answer, but hopefully someone else who understands the designer better
could explain why the designer is still having trouble, \0ven though
there's a parameterless constructor.

Pete
Jun 26 '07 #4

P: n/a
Hi Pete. Yes, my constructors are parameterless. The classes are very
simple
and I already made the test. Commented all inner class code and tried
with generics
and without it. Only work without generics.

In my mind, the designer tries to instantiate the base class and fails
because it
doesn't know what to put in the generic parameter.

I hope you're right. Someone who understands the designer....

Cassio Tavares

On Jun 26, 6:25 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Tue, 26 Jun 2007 14:12:47 -0700, CassioT <cass...@gmail.comwrote:
On 26 jun, 17:39, "Smokey Grindle" <nos...@nospam.comwrote:
the designer has to be able to instanciate the form itself for it to
work in
the designer... if it cant do this, the form wont load
So, I think the designer doesn't know what to pass in the generic
parameter.

What generic parameter? You specify the generic parameter in your class
declaration. As long as you're trying to instantiate the derived type
rather than the generic type, I don't see how that's an issue.

Do you have a parameterless constructor for your derived type?

I understand the need for the designer to be able to instantiate the
object, but if you have a parameterless constructor, I would think that
would be sufficient. If you do and it still doesn't work, I don't have an
answer, but hopefully someone else who understands the designer better
could explain why the designer is still having trouble, even though
there's a parameterless constructor.

Pete

Jun 27 '07 #5

P: n/a
On Tue, 26 Jun 2007 21:46:10 -0700, CassioT <ca*****@gmail.comwrote:
Hi Pete. Yes, my constructors are parameterless. The classes are very
simple
and I already made the test. Commented all inner class code and tried
with generics
and without it. Only work without generics.
When you say you tested it "without generics", did you replace the generic
base class with a different concrete class derived from Form? Or did you
just replace it with Form itself?

I ask because it's not clear from your description exactly how you did the
test, and it could be that the problem you're having isn't actually
related to generics per se.
In my mind, the designer tries to instantiate the base class and fails
because it
doesn't know what to put in the generic parameter.
But that's what I don't understand. The base class isn't the generic
class. It's a fully-qualified class, just as concrete as any other
class. The designer doesn't need to know what to put in the generic
parameter; you've already put that there already in your class definition.
I hope you're right. Someone who understands the designer....
I hope so. :)

I apologize for not trying it myself. It's not like it would be all that
hard to test here, but I've been spending some time trying to wrap my head
around Apple's Cocoa programming environment, and I'm trying my best to
not start up Windows today. Too distracting, 'cause I wind up wasting a
lot of time messing around with stuff that's interesting but not
productive in the short-term. :)

Pete
Jun 27 '07 #6

P: n/a
Sorry Pete if I was not clear enough. The base class is the generic
class.
public BaseForm<T: Form
{}

public MyForm : BaseForm<MyType>
{}

MyForm is the form that doesn't open in the designer. But using...

public BaseForm : Form
{}

public MyForm : BaseForm
{}

it opens.

But you made me think. :)

The base form, has the generic parameter, and opens in the
designer!!!

Maybe there is one more thing that I didn't told you. They are in
different
assemblies.

I will do more tests. I will copy all the code to the same assembly to
see what
happens.

You don't need to apologize Pete. You're already doing too much
talking with me
here. And I never heard about Apple's Cocoa before. :)

Thank you.

On 27 jun, 03:08, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
On Tue, 26 Jun 2007 21:46:10 -0700, CassioT <cass...@gmail.comwrote:
Hi Pete. Yes, my constructors are parameterless. The classes are very
simple
and I already made the test. Commented all inner class code and tried
with generics
and without it. Only work without generics.

When you say you tested it "without generics", did you replace the generic
base class with a different concrete class derived from Form? Or did you
just replace it with Form itself?

I ask because it's not clear from your description exactly how you did the
test, and it could be that the problem you're having isn't actually
related to generics per se.
In my mind, the designer tries to instantiate the base class and fails
because it
doesn't know what to put in the generic parameter.

But that's what I don't understand. The base class isn't the generic
class. It's a fully-qualified class, just as concrete as any other
class. The designer doesn't need to know what to put in the generic
parameter; you've already put that there already in your class definition.
I hope you're right. Someone who understands the designer....

I hope so. :)

I apologize for not trying it myself. It's not like it would be all that
hard to test here, but I've been spending some time trying to wrap my head
around Apple's Cocoa programming environment, and I'm trying my best to
not start up Windows today. Too distracting, 'cause I wind up wasting a
lot of time messing around with stuff that's interesting but not
productive in the short-term. :)

Pete

Jun 27 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.