TargetFrameworkAttribute 類別

定義

識別編譯特定組件時使用的目標 .NET 版本。Identifies the version of .NET that a particular assembly was compiled against.

public ref class TargetFrameworkAttribute sealed : Attribute
public sealed class TargetFrameworkAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
public sealed class TargetFrameworkAttribute : Attribute
type TargetFrameworkAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)>]
type TargetFrameworkAttribute = class
    inherit Attribute
Public NotInheritable Class TargetFrameworkAttribute
Inherits Attribute
繼承
TargetFrameworkAttribute
屬性

備註

TargetFrameworkAttribute類別會提供一個屬性,您可以將它套用至元件,以指出建立元件時所針對的 .net 執行階段版本。The TargetFrameworkAttribute class provides an attribute that you can apply to an assembly to indicate the version of the .NET runtime against which the assembly was built. 例如,下列範例會將套用 TargetFrameworkAttribute 至元件,以表示它是使用建立的 .NET Framework 4.NET Framework 4For example, the following example applies the TargetFrameworkAttribute to an assembly to indicate that it was built using .NET Framework 4.NET Framework 4.

using System;
using System.Runtime.Versioning;

[assembly:TargetFramework(".NETFramework,Version=v4.0")]

namespace MyCompany.Utilities
{
   public class StringLibrary
   {
      // Members defined here.
   }
}
Imports System.Runtime.Versioning

<Assembly:TargetFramework(".NETFramework,Version=v4.0)")>

Namespace MyCompany.Utilities
   Public Class StringLibrary
      ' Members defined here.
   End Class
End Namespace

類別的函式 TargetFrameworkAttribute 具有單一參數, frameworkName 可指定用來建立元件的 .net 版本。The TargetFrameworkAttribute class constructor has a single parameter, frameworkName, that specifies the .NET version against which the assembly was built. 此參數會對應至 FrameworkName 屬性。This parameter maps to the FrameworkName property. 此外, TargetFrameworkAttribute 屬性也可以指定屬性, FrameworkDisplayName 以提供更具描述性的 .net 版本字串,適合顯示給元件的用戶端。In addition, the TargetFrameworkAttribute attribute can specify a FrameworkDisplayName property to provide a more descriptive .NET version string that is suitable for displaying to clients of the assembly. 下列範例會將套用 TargetFrameworkAttribute 至元件,並指派這兩個屬性值來表示元件是使用建立的 .NET Framework 4.NET Framework 4The following example applies the TargetFrameworkAttribute to an assembly and assigns both property values to indicate that the assembly was built using .NET Framework 4.NET Framework 4.

using System;
using System.Runtime.Versioning;

[assembly:TargetFramework(".NETFramework,Version=v4.0", 
          FrameworkDisplayName = ".NET Framework, Version 4.0")]

namespace MyCompany.Utilities
{
   public class StringLibrary
   {
      // Members defined here.
   }
}
Imports System.Runtime.Versioning

<Assembly:TargetFramework(".NETFramework,Version=v4.0)", _
          FrameworkDisplayName := ".NET Framework, Version 4.0")>

Namespace MyCompany.Utilities
   Public Class StringLibrary
      ' Members defined here.
   End Class
End Namespace

建構函式

TargetFrameworkAttribute(String)

透過指定建置組件時使用的 .NET 版本,以初始化 TargetFrameworkAttribute 類別的執行個體。Initializes an instance of the TargetFrameworkAttribute class by specifying the .NET version against which an assembly was built.

屬性

FrameworkDisplayName

取得建置組件時使用之 .NET 版本的顯示名稱。Gets the display name of the .NET version against which an assembly was built.

FrameworkName

取得建置特定組件時使用之 .NET 版本的名稱。Gets the name of the .NET version against which a particular assembly was compiled.

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()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。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)

適用於

另請參閱