.NET中的多个基类 [英] Multiple base classes in .NET

查看:154
本文介绍了.NET中的多个基类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在C ++ref下阅读了MSDN中的一个模糊信息。关键字,其中指出:


"在CLR对象模型下,仅支持公共单继承。


这是否意味着没有.NET类可以支持多重继承。例如,在
C ++中,我注意到如果你使用

" ref",编译器会标记错误。具有多个基类的类上的关键字。这支持上面的

报价。但是,在CodeClass2.Bases下,属性(部分VS

可扩展性模型),它声明:


基础是超级类型的CodeElements。对于Visual Basic和Visual C#

,集合中始终只有一个元素,除非代码类型

是CodeInterface。


当然这是正确的,因为这些语言只支持单(类)

继承。但是,对于基于上面第一个引用的所有.NET类,它应该是真的。因此我的问题是这个。我想通过调用

" CodeClass2.Bases.Item(1)"来检索任意代码文件中任意类的基类

类。这在我的测试中有效,但理论上它对所有语言总是有效吗?假设我正在瞄准的课程总是一个

..NET课程。在此先感谢。

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.

推荐答案

Larry Smith写道:
Larry Smith wrote:

我刚刚读了一篇文章在MSDN下的C ++ref中关键字,其中指出:


"在CLR对象模型下,仅支持公共单继承。


这是否意味着没有.NET类可以支持多重继承。
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.



我相信如此。

I belive so.


这当然是正确的,因为这些语言只支持单一(类)

继承。但是,对于基于上面第一个引用的所有.NET类,它应该是真的。因此我的问题是这个。我想通过调用

" CodeClass2.Bases.Item(1)"来检索任意代码文件中任意类的基类

类。这在我的测试中有效,但理论上它对所有语言总是有效吗?假设我正在瞄准的类当然是一个

.NET类。提前致谢。
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.



如果是任意代码,那么我相信你应该使用

Type BaseType。


显然它只返回一种类型。


Arne

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写道,在14-7-2007 1:49:
* Larry Smith wrote, On 14-7-2007 1:49:

我刚刚在C ++ref下阅读了MSDN中的一个模糊信息。关键字,其中指出:


"在CLR对象模型下,仅支持公共单继承。


这是否意味着没有.NET类可以支持多重继承。例如,在
C ++中,我注意到如果你使用

" ref",编译器会标记错误。具有多个基类的类上的关键字。这支持上面的

报价。但是,在CodeClass2.Bases下,属性(部分VS

可扩展性模型),它声明:


基础是超级类型的CodeElements。对于Visual Basic和Visual C#

,集合中始终只有一个元素,除非代码类型

是CodeInterface。


当然这是正确的,因为这些语言只支持单(类)

继承。但是,对于基于上面第一个引用的所有.NET类,它应该是真的。因此我的问题是这个。我想通过调用

" CodeClass2.Bases.Item(1)"来检索任意代码文件中任意类的基类

类。这在我的测试中有效,但理论上它对所有语言总是有效吗?假设我正在瞄准的类当然是一个

.NET类。提前致谢。
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.



Visual Studio可扩展性模型还支持非CLR语言

(例如本机C ++),因此它支持多重继承。


.NET类型不支持多重继承,因为你已经发现了b $ b。我已经读过几个传言说多重继承将会在未来的版本中重新进入CLR ...


Jesse

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...

Jesse


>我刚刚在C ++ref中读取了MSDN中的一个blurb。关键字,表示
>I just read a blurb in MSDN under the C++ "ref" keyword which states

>表示:

"在CLR对象模型下,只有公共单一继承是支持的。

这是否意味着没有.NET类可以支持多重继承。
>that:

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

Does this mean that no .NET class can ever support multiple inheritance.



我相信如此。


I belive so.


>这当然是正确的,因为这些语言只支持单一(类)
继承。但是,基于上面的第一个引用,所有.NET类都应该如此。因此我的问题是这个。我想通过调用
CodeClass2.Bases.Item(1)来检索任意代码文件中任意类的
基类。这在我的测试中有效,但它总是在理论上适用于所有语言,假设我正在瞄准的课程当然是.NET课程。提前致谢。
>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.



如果是任意代码,那么我相信你应该使用

类型BaseType。


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



感谢您的提示。它可能在以后证明有用,但目前我可能无法检索类型。 (因为我的应用程序处理原始源文件

,甚至可能尚未编译)。

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).


这篇关于.NET中的多个基类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆