ComCompatibleVersionAttribute 类

定义

向 COM 客户端指示程序集当前版本中的所有类与该程序集早期版本中的类兼容。Indicates to a COM client that all classes in the current version of an assembly are compatible with classes in an earlier version of the assembly.

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

示例

下面的示例演示如何在版本号较高的程序集中指定程序集版本1.0.0.0。The following example shows how to specify assembly version 1.0.0.0 in an assembly with a higher version number. 无论使用哪个新的程序集版本,程序集中的所有 Clsid 都是使用版本1.0.0.0 生成的,而不是使用当前程序集版本。Regardless of the new assembly version, all CLSIDs in the assembly are generated using version 1.0.0.0 instead of using the current assembly version.

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

注解

可以将此特性应用于程序集。You can apply this attribute to assemblies.

默认情况下, tlbexp.exe (类型库导出程序)使用程序集的版本号来计算类标识符(clsid)。By default, the Tlbexp.exe (Type Library Exporter) uses an assembly's version number to calculate class identifiers (CLSIDs). 每次导出新的程序集版本时,所有公共的 COM 可见类都接收新的 Clsid。All public, COM-visible classes receive new CLSIDs each time you export a new assembly version.

可以应用 ComCompatibleVersionAttribute 特性来强制程序集的当前版本中的所有类的 Clsid 与早期版本的程序集中类的 Clsid 相同。You can apply the ComCompatibleVersionAttribute attribute to force all CLSIDs for classes in the current version of an assembly to be the same as CLSIDs for classes in an earlier version of the assembly. 只要 Clsid 保持不变,旧的 COM 应用程序就可以在卸载原始程序集之后使用兼容的程序集的更高版本。As long as the CLSIDs remain the same, a legacy COM application can use the later version of a compatible assembly after you uninstall the original assembly. 如果将 System.Runtime.InteropServices.GuidAttribute 应用到类来显式设置其 CLSID,则 ComCompatibleVersionAttribute 不起作用。If you apply the System.Runtime.InteropServices.GuidAttribute to a class to explicitly set its CLSID, the ComCompatibleVersionAttribute has no effect.

此属性的属性组合在一起构成程序集版本的四个部分。The properties of this attribute combine to form the four parts of an assembly version. 请始终指定当前程序集向后兼容的最低版本,使版本用于计算程序集中的所有 Clsid。Always specify the lowest version that the current assembly is backward compatible with so that version is used to calculate all CLSIDs in the assembly.

构造函数

ComCompatibleVersionAttribute(Int32, Int32, Int32, Int32)

使用程序集的主版本、次版本、内部版本号和修订号初始化 ComCompatibleVersionAttribute 类的新实例。Initializes a new instance of the ComCompatibleVersionAttribute class with the major version, minor version, build, and revision numbers of the assembly.

属性

BuildNumber

获取程序集的生成号。Gets the build number of the assembly.

MajorVersion

获取程序集的主版本号。Gets the major version number of the assembly.

MinorVersion

获取程序集的次版本号。Gets the minor version number of the assembly.

RevisionNumber

获取程序集的修订号。Gets the revision number of the assembly.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。Returns a value that indicates whether this instance is equal to a specified object.

(继承自 Attribute)
GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

(继承自 Attribute)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

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

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

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

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

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

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

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

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅