473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inherit form and generics

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
6 3060
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.goo glegroups.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

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.goo glegroups.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
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
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...@nn owslpianmk.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
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
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...@nn owslpianmk.comw rote:
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
2452
by: Bernardo Heynemann | last post by:
How can I use Generics? How can I use C# 2.0? I already have VS.NET 2003 Enterprise Edition and still can´t use generics... I´m trying to make a generic collection myCollection<vartype> and still no can do... Any info would be great!
6
2899
by: Mohammad-Reza | last post by:
I wrote a component using class library wizard. In my component i want to in order to RightToLeft property do some works. I can find out if user set this property to Yes or No, But if He/She set it to Inherit I must examine its parent RightToLeft property(if i`m wrong please tell me) but in this component that inherits from System.ComponentModel.Component, How can i find parent??? In UserControls we can simply use Parent property but in...
44
16935
by: Frank Rizzo | last post by:
Any ideas?
4
428
by: David | last post by:
I have trying to have a webform inherit controls from another form and can't get it to work Say I have a form that saves the person's demographic info. ****one.aspx**** //I have an object to save the person's name in code behind protected void SavePersonInfo(Person p)
2
1355
by: Wu Qinliang | last post by:
I created a Windows form named myform1, and put some controls on it. I need another form named myform2. Because myform2 is similar to myform1, so I want myform2 to inherit from myform1, i.e: Public Class myform2 inherits myform1 ....... End Class
23
2534
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics vs C++ templates. Does anyone knows a workaround to do this ? Thx : public class C<T> { private T myValue;
12
2729
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as it defines the language more completely. Great to use.
9
5967
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal Experience Only, Please. ...
13
3809
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The problem I'm running into has to do with the differences in implementations of Generics between the two...
0
8009
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7939
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8428
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8078
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8299
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
3919
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.