LocalizableAttribute.IsLocalizable 屬性

定義

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

C#
public bool IsLocalizable { get; }

屬性值

如果屬性應該當地語系化則為 true,否則為 false

範例

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

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

C#
// 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.
 }

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另請參閱