LocalizableAttribute 類別

定義

指定屬性或參數是否應該當地語系化。 此類別無法獲得繼承。

public ref class LocalizableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class LocalizableAttribute : Attribute
public sealed class LocalizableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type LocalizableAttribute = class
    inherit Attribute
type LocalizableAttribute = class
    inherit Attribute
Public NotInheritable Class LocalizableAttribute
Inherits Attribute
繼承
LocalizableAttribute
屬性

範例

下列範例會將 message 參數標示為需要當地語系化。

public static void ShowMessage([Localizable(true)] string message)

下列範例會將屬性標示為需要當地語系化。

public:
   property int MyProperty 
   {
      [Localizable(true)]
      int get()
      {
         // Insert code here.
         return 0;
      }

      void set( int value )
      {
         // Insert code here.
      }
   }
[Localizable(true)]
 public int MyProperty {
    get {
       // Insert code here.
       return 0;
    }
    set {
       // Insert code here.
    }
 }
<Localizable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property

下一個範例示範如何檢查 LocalizableAttribute 的值。 MyProperty 首先,程式碼會取得 PropertyDescriptorCollection 具有 物件之所有屬性的 。 然後,程式碼會從 PropertyDescriptorCollection 取得 MyProperty 。 接下來,它會傳回此屬性的屬性,並將其儲存在屬性變數中。

最後,程式碼會將 設定 myAttribute 為 中的 AttributeCollectionLocalizableAttribute ,並檢查屬性是否需要當地語系化。

// Gets the attributes for the property.
AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes;

// Checks to see if the property needs to be localized.
LocalizableAttribute^ myAttribute = dynamic_cast<LocalizableAttribute^>(attributes[ LocalizableAttribute::typeid ]);
if ( myAttribute->IsLocalizable )
{
   // Insert code here.
}
// Gets the attributes for the property.
AttributeCollection attributes = 
TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

// Checks to see if the property needs to be localized.
LocalizableAttribute myAttribute = 
(LocalizableAttribute)attributes[typeof(LocalizableAttribute)];
if(myAttribute.IsLocalizable) {
// Insert code here.
}
' Gets the attributes for the property.
Dim attributes As AttributeCollection = TypeDescriptor.GetProperties(Me)("MyProperty").Attributes

' Checks to see if the property needs to be localized.
Dim myAttribute As LocalizableAttribute = CType(attributes(GetType(LocalizableAttribute)), LocalizableAttribute)
If myAttribute.IsLocalizable Then
     ' Insert code here.
End If

備註

為元件產生程式碼時,標示為 已設定 LocalizableAttributetrue 的成員會將其屬性值儲存在資源檔中。 您可以當地語系化這些資源檔,而不需修改程式碼。

根據預設,沒有可當地語系化屬性或標示 LocalizableAttributefalse 的成員,如果資料類型允許,其屬性值會保存至程式碼。 否則,如果主要元件設定 Localizable 為 ,則所有屬性都會保存到資源檔。 預設為 false

注意

當您將 屬性 LocalizableAttributetrue 標示為 時,這個屬性的值會設定為常數成員 Yes 。 對於標示 LocalizableAttributefalse 的屬性,此值為 No 。 因此,當您想要在程式碼中檢查此屬性的值時,必須將 屬性指定為 LocalizableAttribute.YesLocalizableAttribute.No

如需詳細資訊,請參閱屬性

建構函式

LocalizableAttribute(Boolean)

初始化 LocalizableAttribute 類別的新執行個體。

欄位

Default

指定預設值,即 No。 這個 static 欄位是唯讀的。

No

指定屬性不應該當地語系化。 這個 static 欄位是唯讀的。

Yes

指定屬性應該當地語系化。 這個 static 欄位是唯讀的。

屬性

IsLocalizable

取得值,表示是否應該將屬性當地語系化。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 LocalizableAttribute

GetHashCode()

傳回這個執行個體的雜湊碼。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。

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)

適用於

另請參閱