473,498 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending an Abstract class that uses a Generic Parameter

BBM
Hi,

I have a situation where I would like to extend an abstract (MustInherit)
class that uses a Generic parameter. The class declaration looks like this...

Public MustInherit Class BaseClass(Of T)

There is an Overridable method in this class that I would like to override.
There will be many classes in my program that need to derive from
BaseClass(Of T) but I only need one version of the Override method.

I'd like to do this...

Public MustInherit Class DerivedAbstractClass(of T) : Inherits BaseClass(of T)

I'd put my version of the Overrideable method here, and then use this class
as the parent of all my derived classes.

But the compiler says I cannot have a generic parameter in the Inherits part
of the declaration of my class.

Am I stuck with copying the same Override method into every class that
derives from BaseClass(Of T)?

Any suggestions?

Thanks.

BBM
Sep 8 '06 #1
3 2969
>But the compiler says I cannot have a generic parameter in the Inherits part
>of the declaration of my class.
Can you post the exact error message you're getting and actual code
that will reproduce it? The following compiles fine here

MustInherit Class BaseClass(Of T)
End Class

MustInherit Class DerivedAbstractClass(Of T)
Inherits BaseClass(Of T)
End Class

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 8 '06 #2
Hi BBM,

I performed a test and didn't encounter a compilation error on the
following lines of code either.

Public MustInherit Class BaseClass(Of T)

End Class

public MustInherit Class DerivedAbstractClass(Of T)
Inherits BaseClass(Of T)

End Class

You may provide more actual code that reproduce the problem.
I'd put my version of the Overrideable method here, and then use this
class
as the parent of all my derived classes.

Why not implement the method in the BaseClass directly and then use the
BaseClass as the parent of all your derived classes?

Hope this helps.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 11 '06 #3
BBM
Hi Mattias:

In preparing to reply to your request for more information, I stumbled upon
my mistake. The original class I was deriving from had a constraint on the
generic parameter and the compiler was complaining that the defintion of my
derived abstract class didn't comply with the constraint.

I added the constraint to my definition and it's working fine.

Thanks for helping me with this.

"Mattias Sjögren" wrote:
But the compiler says I cannot have a generic parameter in the Inherits part
of the declaration of my class.

Can you post the exact error message you're getting and actual code
that will reproduce it? The following compiles fine here

MustInherit Class BaseClass(Of T)
End Class

MustInherit Class DerivedAbstractClass(Of T)
Inherits BaseClass(Of T)
End Class

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
6623
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
5
2930
by: needin4mation | last post by:
Hi, I read this in a book about the Xml classes in c#: "These classes are abstract and therefore must be extended." I just wanted to know what this statement means. I know it is not in...
4
1555
by: hazz | last post by:
public abstract class FormShellApplication<TWorkItem, TShell> : WindowsFormsApplication<TWorkItem, TShell> where TWorkItem : WorkItem, new() where TShell : Form thank you, -hazz
11
2466
by: herpers | last post by:
Hello, I probably don't see the obvious, but maybe you can help me out of this mess. The following is my problem: I created two classes NormDistribution and DiscDistribution. Both classes...
4
1251
by: Confused Newbie | last post by:
I'm converting an app written in VB 2003 to 2005 and need advice for how to deal with this situation: The app has a number of "manager" classes that handle the data access. They all have...
7
4452
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
6
3294
by: Nindi | last post by:
5 Files Singleton.h The Singleton Factory.h The factory creating new objects. The Base class of the hierachy stores a typelist identifying the signature of the constructors to be called...
4
4367
by: dascandy | last post by:
Hi, For a project I'm working on I'm kind-of-hacking my way around deriving a class from an interface or such to create a mock, but instead creating the mock directly. It is usable as the...
2
1374
by: alireza6485 | last post by:
Hi, Can you please help me with my assignment.I coded it and it runs I just need someone to help me a bit. The behaviour of monekys and human beings are Similar (Breeding and breathing are...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7203
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...
1
6885
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...
0
7379
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...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1417
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 ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
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...

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.