ComCompatibleVersionAttribute ComCompatibleVersionAttribute ComCompatibleVersionAttribute ComCompatibleVersionAttribute Class

定义

向 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
继承
ComCompatibleVersionAttributeComCompatibleVersionAttributeComCompatibleVersionAttributeComCompatibleVersionAttribute
属性

示例

下面的示例演示如何以更高版本的版本号的程序集中指定程序集版本 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. 无论何种新的程序集版本,而不使用当前的程序集版本使用 1.0.0.0 版本生成程序集中的所有 Clsid。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
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于类,以显式设置其 CLSIDComCompatibleVersionAttribute不起作用。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(Int32, Int32, Int32, Int32) ComCompatibleVersionAttribute(Int32, Int32, Int32, Int32) 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 BuildNumber BuildNumber BuildNumber

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

MajorVersion MajorVersion MajorVersion MajorVersion

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

MinorVersion MinorVersion MinorVersion MinorVersion

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

RevisionNumber RevisionNumber RevisionNumber RevisionNumber

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

TypeId TypeId TypeId TypeId

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

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

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

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

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

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

显式界面实现

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

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

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

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

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

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

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

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

(Inherited from Attribute)

适用于

另请参阅