IDispatchImplAttribute 类

注意:此类现在已过时。

指示当向 COM 公开双重接口和调度接口时公共语言运行库使用何种 IDispatch 实现。

**命名空间:**System.Runtime.InteropServices
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class, Inherited:=False)> _
<ObsoleteAttribute("This attribute is deprecated and will be removed in a future version.", False)> _
Public NotInheritable Class IDispatchImplAttribute
    Inherits Attribute
用法
Dim instance As IDispatchImplAttribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false)] 
[ObsoleteAttribute("This attribute is deprecated and will be removed in a future version.", false)] 
public sealed class IDispatchImplAttribute : Attribute
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class, Inherited=false)] 
[ObsoleteAttribute(L"This attribute is deprecated and will be removed in a future version.", false)] 
public ref class IDispatchImplAttribute sealed : public Attribute
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false) */ 
/** @attribute ObsoleteAttribute("This attribute is deprecated and will be removed in a future version.", false) */ 
public final class IDispatchImplAttribute extends Attribute
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class, Inherited=false) 
ObsoleteAttribute("This attribute is deprecated and will be removed in a future version.", false) 
public final class IDispatchImplAttribute extends Attribute

备注

可将该属性应用于类或程序集。

只有在需要显式实现时才应设置此属性。当将属性设置为 CompatibleImpl 时,通过向 COM 的 CreateStdDispatch API 传递对象的类型信息来提供 IDispatch 实现。当将属性设置为 InternalImpl 时,公共语言运行库将提供 IDispatch 实现。将属性设置为 SystemDefinedImpl 使运行库可以选择适当的实现。当对程序集使用该属性时,属性将应用到程序集内定义的所有类。当对单个类使用该属性时,属性只应用到该类公开的接口,并重写所有程序集级设置。

示例

下面的示例演示如何应用 IDispatchImplAttribute 来选择由公共语言运行库提供的 IDispatch 实现。

Imports System
Imports System.Runtime.InteropServices
' by default all classes in this assembly will use COM implementaion 
<Assembly: IDispatchImpl(IDispatchImplType.CompatibleImpl)> 

Module MyNamespace
    ' But this class will use runtime implementaion
    <IDispatchImpl(IDispatchImplType.InternalImpl)> _
    Public Class c
        '
    End Class

End Module
using System;
using System.Runtime.InteropServices;
// by default all classes in this assembly will use COM implementaion 
[assembly:IDispatchImpl(IDispatchImplType.CompatibleImpl)]

namespace MyNamespace
{
    // But this class will use runtime implementaion
    [IDispatchImpl(IDispatchImplType.InternalImpl)]
    class MyClass
    {
        //
    }
}
using namespace System;
using namespace System::Runtime::InteropServices;

// by default all classes in this assembly will use COM implementaion
//   // But this class will use runtime implementaion

[assembly:IDispatchImpl(IDispatchImplType::CompatibleImpl)];
[IDispatchImpl(IDispatchImplType::InternalImpl)]
ref class MyClass{};
import System.*;
import System.Runtime.InteropServices.*;

// by default all classes in this assembly will use COM implementaion 
/** @assembly IDispatchImpl(IDispatchImplType.CompatibleImpl)
 */
// But this class will use runtime implementaion
/** @attribute IDispatchImpl(IDispatchImplType.InternalImpl)
 */
   class MyClass
   {
       //
   } //MyClass

继承层次结构

System.Object
   System.Attribute
    System.Runtime.InteropServices.IDispatchImplAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:1.0、1.1
在 2.0 中过时(编译器警告)

请参见

参考

IDispatchImplAttribute 成员
System.Runtime.InteropServices 命名空间
IDispatchImplType