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の値を確認する方法を示します。 まず、コードは、オブジェクトのすべてのプロパティを含む PropertyDescriptorCollection を取得します。 その後、コードはPropertyDescriptorCollectionからMyPropertyされます。 次に、このプロパティの属性を返し、属性変数に保存します。

最後に、コードはmyAttributeAttributeCollection内のLocalizableAttributeの値に設定し、プロパティをローカライズする必要があるかどうかを確認します。

// 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 に設定されたメンバーのプロパティ値がリソース ファイルに保存されます。 これらのリソース ファイルは、コードを変更せずにローカライズできます。

既定では、ローカライズ可能な属性を持たないメンバー、またはfalseに設定されたLocalizableAttributeでマークされているメンバーは、データ型で許可されている場合、そのプロパティ値がコードに保持されます。 それ以外の場合、メイン コンポーネントが Localizableに設定されている場合、すべてのプロパティがリソース ファイルに保持されます。 既定値は false です。

Note

LocalizableAttributetrue に設定してプロパティをマークすると、この属性の値は定数メンバー Yesに設定されます。 LocalizableAttributefalse に設定されたプロパティの場合、値はNo。 したがって、コードでこの属性の値を確認する場合は、属性を LocalizableAttribute.Yes または LocalizableAttribute.Noとして指定する必要があります。

詳細については、「属性」を参照してください。

コンストラクター

名前 説明
LocalizableAttribute(Boolean)

LocalizableAttribute クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
Default

既定値 ( No) を指定します。 この static フィールドは読み取り専用です。

No

プロパティをローカライズしないことを指定します。 この static フィールドは読み取り専用です。

Yes

プロパティをローカライズすることを指定します。 この static フィールドは読み取り専用です。

プロパティ

名前 説明
IsLocalizable

プロパティをローカライズするかどうかを示す値を取得します。

TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

指定したオブジェクトの値が現在の LocalizableAttributeと等しいかどうかを返します。

GetHashCode()

このインスタンスのハッシュ コードを返します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

この属性が既定であるかどうかを判断します。

Match(Object)

派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

名前 説明
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください