.NET Framework Class Library  

LocalizableAttribute Class

Specifies whether a property should be localized.

For a list of all members of this type, see LocalizableAttribute Members.

System.Object
   System.Attribute
      System.ComponentModel.LocalizableAttribute

[Visual Basic]
<AttributeUsage(AttributeTargets.All)>
NotInheritable Public Class LocalizableAttribute
   Inherits Attribute
[C#]
[AttributeUsage(AttributeTargets.All)]
public sealed class LocalizableAttribute : Attribute
[C++]
[AttributeUsage(AttributeTargets::All)]
public __gc __sealed class LocalizableAttribute : public Attribute
[JScript]
public
   AttributeUsage(AttributeTargets.All)
class LocalizableAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

Remarks

When code is generated for a component, members that are marked with the LocalizableAttribute constructor of the value true have their property values saved in resource files. You can localize these resource files without modifying the code.

By default, members that have no localizable attribute or are marked with the LocalizableAttribute constructor of the value false will have their property values persisted to code, if the data type allows. Otherwise, if the main component is set to Localizable, all properties will be persisted to the resource file. The default is false.

Note   When you mark a property with the LocalizableAttribute constructor of the value true, the value of this attribute is set to the constant member Yes. For a property marked with the LocalizableAttribute constructor of the value false, the value is 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 Overview and Extending Metadata Using Attributes.

Example

[Visual Basic, C#, JScript] The following example marks a property as needing to be localized.

[Visual Basic] 
<Localizable(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set 
End Property


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

[Visual Basic, C#, JScript] The next example shows how to check the value of the LocalizableAttribute for MyProperty. First, the code gets a PropertyDescriptorCollection with all the properties for the object. Then, the code gets MyProperty from the PropertyDescriptorCollection. Next, it returns the attributes for this property and saves them in the attributes variable.

[Visual Basic, C#, JScript] Finally, the code sets myAttribute to the value of the LocalizableAttribute in the AttributeCollection and checks whether the property needs to be localized.

[Visual Basic] 
' 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

[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.
}

[JScript] 
// Gets the attributes for the property.
var attributes : AttributeCollection = TypeDescriptor.GetProperties(this)["MyProperty"].Attributes

// Checks to see if the property needs to be localized.
var myAttribute : LocalizableAttribute = LocalizableAttribute(attributes(LocalizableAttribute))
if(myAttribute.IsLocalizable){
     // Insert code here.
}

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

LocalizableAttribute Members | System.ComponentModel Namespace | Attribute | PropertyDescriptor | AttributeCollection | PropertyDescriptorCollection