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)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱