LocalizableAttribute 類別

定義

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

public ref class LocalizableAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class LocalizableAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
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.
        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

下一個範例說明如何檢查 的值LocalizableAttributeMyProperty 首先,程式碼會取得包含所有物件屬性的 a PropertyDescriptorCollection 。 接著,程式碼會從 MyPropertyPropertyDescriptorCollection。 接著,它會回傳該屬性的屬性,並將其儲存在屬性變數中。

最後,程式碼將 的值LocalizableAttributemyAttribute為 ,AttributeCollection並檢查屬性是否需要局部化。

// 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

備註

當為元件產生程式碼時,標記為 set LocalizableAttribute 的成員會 true 將其屬性值儲存在資源檔案中。 你可以在不修改程式碼的情況下本地化這些資源檔案。

預設情況下,若成員沒有可本地化屬性或以 LocalizableAttributefalse 標記為 ,若資料型態允許,其屬性值會持續存在程式碼中。 否則,若主要元件設定為 Localizable,所有屬性都會持久化到資源檔案。 預設值為 false

Note

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

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

建構函式

名稱 Description
LocalizableAttribute(Boolean)

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

欄位

名稱 Description
Default

指定預設值,即 No。 此 static 欄位為唯讀。

No

規定財產不應被限定在地。 此 static 欄位為唯讀。

Yes

規定房產應為地方化。 此 static 欄位為唯讀。

屬性

名稱 Description
IsLocalizable

會得到一個值,指示該物業是否應該被在地化。

TypeId

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

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

回傳給定物件的值是否等於當前 LocalizableAttribute值。

GetHashCode()

傳回這個實例的哈希碼。

GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

判斷此屬性是否為預設值。

Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 Description
_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)

適用於

另請參閱