LocalizableAttribute 類別

定義

指定是否應該當地語系化屬性。Specifies whether a property should be localized. 這個類別無法被繼承。This class cannot be inherited.

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

範例

下列範例會將屬性標示為需要當地語系化。The following example marks a property as needing to be localized.

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

下一個範例顯示如何檢查的值LocalizableAttributeMyPropertyThe next example shows how to check the value of the LocalizableAttribute for MyProperty. 首先, 程式碼會取得PropertyDescriptorCollection具有物件之所有屬性的。First, the code gets a PropertyDescriptorCollection with all the properties for the object. 然後, 程式碼會MyProperty PropertyDescriptorCollection從取得。Then, the code gets MyProperty from the PropertyDescriptorCollection. 接下來, 它會傳回這個屬性的屬性, 並將其儲存在 attributes 變數中。Next, it returns the attributes for this property and saves them in the attributes variable.

最後, 程式碼會myAttribute將設定為LocalizableAttributeAttributeCollection的值, 並檢查屬性是否需要當地語系化。Finally, the code sets myAttribute to the value of the LocalizableAttribute in the AttributeCollection and checks whether the property needs to be localized.

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

備註

為元件產生程式碼時, 以LocalizableAttribute true設定的標記成員會將其屬性值儲存在資源檔中。When code is generated for a component, members that are marked with the LocalizableAttribute set to true have their property values saved in resource files. 您可以將這些資源檔當地語系化, 而不需要修改程式碼。You can localize these resource files without modifying the code.

根據預設, 如果資料類型允許, 則沒有可LocalizableAttribute false當地語系化屬性或標記為的成員會將其屬性值保存至程式碼。By default, members that have no localizable attribute or are marked with the LocalizableAttribute set to false will have their property values persisted to code, if the data type allows. 否則, 如果主要元件設定為Localizable, 則所有屬性都會保存到資源檔中。Otherwise, if the main component is set to Localizable, all properties will be persisted to the resource file. 預設為 falseThe default is false.

注意

當您將設定為的LocalizableAttribute屬性標記為true時, 這個屬性的值會設定為常數成員。 YesWhen you mark a property with the LocalizableAttribute set to true, the value of this attribute is set to the constant member Yes. 對於以設定為LocalizableAttribute false的標記的屬性, 此值No為。For a property marked with the LocalizableAttribute set to false, the value is No. 因此, 當您想要在程式碼中檢查這個屬性的值時, 您必須將屬性指定LocalizableAttribute.YesLocalizableAttribute.No或。Therefore, when you want to check the value of this attribute in your code, you must specify the attribute as LocalizableAttribute.Yes or LocalizableAttribute.No.

如需詳細資訊,請參閱屬性For more information, see Attributes.

建構函式

LocalizableAttribute(Boolean)

初始化 LocalizableAttribute 類別的新執行個體。Initializes a new instance of the LocalizableAttribute class.

欄位

Default

指定預設值,即 NoSpecifies the default value, which is No. 這個 static 欄位是唯讀的。This static field is read-only.

No

指定屬性不應該當地語系化。Specifies that a property should not be localized. 這個 static 欄位是唯讀的。This static field is read-only.

Yes

指定屬性應該當地語系化。Specifies that a property should be localized. 這個 static 欄位是唯讀的。This static field is read-only.

屬性

IsLocalizable

取得值,表示是否應該將屬性當地語系化。Gets a value indicating whether a property should be localized.

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,表示指定的物件值是否等於目前的 LocalizableAttributeReturns whether the value of the given object is equal to the current LocalizableAttribute.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

判斷這個屬性是否為預設值。Determines if this attribute is the default.

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)

適用於

另請參閱