Groups | Blog | Home
all groups > dotnet clr > july 2007 >

dotnet clr : Multiple base classes in .NET



Larry Smith
7/13/2007 7:49:20 PM
I just read a blurb in MSDN under the C++ "ref" keyword which states that:

"Under the CLR object model, only public single inheritance is supported".

Does this mean that no .NET class can ever support multiple inheritance. In
C++ for instance I noticed that the compiler flags an error if you use the
"ref" keyword on a class with multiple base classes. This supports the above
quote. However, under the "CodeClass2.Bases" property (part the VS
extensibility model), it states that:

"Bases are super types of CodeElements. For Visual Basic and Visual C#
there is always only one element in the collection except when the code type
is a CodeInterface".

This is true of course since these languages only support single (class)
inheritance. However, it should be true for all .NET classes based on the
first quote above. My issue is therefore this. I want to retrieve the base
class of an arbitrary class in an arbitrary code file by invoking
"CodeClass2.Bases.Item(1)". This works in my testing but will it always work
for all languages in theory, assuming the class I'm targetting is always a
..NET class of course. Thanks in advance.

Arne_Vajhøj
7/13/2007 7:59:19 PM
[quoted text, click to view]

I belive so.

[quoted text, click to view]

If is is arbitrary code, then I belive that you should be using
Type BaseType.

And it is obvious that it will only return one type.

Arne
Larry Smith
7/13/2007 8:19:37 PM
[quoted text, click to view]

Thanks for the tip. It might prove useful later but for the moment I might
not be able to retrieve the "Type" (since my app processes raw source files
before they may have even been compiled yet).

Larry Smith
7/13/2007 8:36:46 PM
[quoted text, click to view]

Thanks for the clarification (appreciated). As for the rumour, I'm not sure
how they'll tackle that given that there already seem to be some built-in
assumptions based on single-inheritance. They could change this of course
but it might cause a lot of problems. Anyway, thanks again.

Jesse Houwing
7/14/2007 2:04:27 AM
* Larry Smith wrote, On 14-7-2007 1:49:
[quoted text, click to view]

The Visual Studio Extensibility model also supports non-CLR languages
(native C++ for example), so it has support for multiple inheritance.

The .NET types do not support multiple inheritance as you've already
found out. I've read a couple of rumors that multiple inheritance will
probably find its way back into the CLR in a future version...

Mark Rae [MVP]
7/14/2007 2:05:30 AM
[quoted text, click to view]

I'd be surprised if we ever see multiple inheritance in C#...

http://blogs.msdn.com/csharpfaq/archive/2004/03/07/85562.aspx
http://www.google.co.uk/search?hl=en&rlz=1T4GGIH_en-GBGB220GB220&q=%22c%23%22+multiple+inheritance&meta=


--
Mark Rae
ASP.NET MVP
http://www.markrae.net
AddThis Social Bookmark Button