ComCompatibleVersionAttribute 类

定义

向 COM 客户端指示程序集当前版本中的所有类与该程序集早期版本中的类兼容。

public ref class ComCompatibleVersionAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)]
public sealed class ComCompatibleVersionAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ComCompatibleVersionAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)>]
type ComCompatibleVersionAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ComCompatibleVersionAttribute = class
    inherit Attribute
Public NotInheritable Class ComCompatibleVersionAttribute
Inherits Attribute
继承
ComCompatibleVersionAttribute
属性

示例

以下示例演示如何在具有更高版本号的程序集中指定程序集版本 1.0.0.0。 无论新程序集版本如何,程序集中的所有 CLSID 都使用版本 1.0.0.0 而不是当前程序集版本生成。

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

[assembly: AssemblyVersion("3.0.0.0")];
[assembly: ComCompatibleVersion(1,0,0,0)];
namespace MyNamespace
{
    public ref class TheClass
    {
        // Insert code.
    };
};
using System;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyVersion("3.0.0.0")]
[assembly: ComCompatibleVersion(1,0,0,0)]
namespace MyNamespace
{
    public class TheClass
    {
        // Insert code.
    }
}
Imports System.Reflection
Imports System.Runtime.InteropServices

<assembly: AssemblyVersion("3.0.0.0")>
<assembly: ComCompatibleVersion(1,0,0,0)>
Namespace MyNamespace
    Public Class TheClass
        ' Insert code.
    End Class
End Namespace

注解

可以将此属性应用于程序集。

默认情况下, Tlbexp.exe (类型库导出程序) 使用程序集的版本号来计算 (CLSID) 的类标识符。 每次导出新的程序集版本时,所有公开的 COM 可见类都会收到新的 CLSID。

可以应用该 ComCompatibleVersionAttribute 属性来强制当前版本的程序集中类的所有 CLSID 与早期版本的程序集中的类的 CLSID 相同。 只要 CLSID 保持不变,旧版 COM 应用程序就可以在卸载原始程序集后使用兼容程序集的更高版本。 如果将类应用于 System.Runtime.InteropServices.GuidAttribute 显式设置其 CLSID,则 ComCompatibleVersionAttribute 不起作用。

此属性的属性组合在一起,构成程序集版本的四个部分。 始终指定当前程序集向后兼容的最低版本,以便该版本用于计算程序集中的所有 CLSID。

构造函数

ComCompatibleVersionAttribute(Int32, Int32, Int32, Int32)

使用程序集的主版本、次版本、内部版本号和修订号初始化 ComCompatibleVersionAttribute 类的新实例。

属性

BuildNumber

获取程序集的生成号。

MajorVersion

获取程序集的主版本号。

MinorVersion

获取程序集的次版本号。

RevisionNumber

获取程序集的修订号。

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。

(继承自 Attribute)
GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于

另请参阅