LocalizableAttribute クラス

定義

プロパティまたはパラメーターをローカライズするかどうかを指定します。 このクラスは継承できません。

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

次の例では、 の値をチェックする方法をLocalizableAttributeMyProperty示します。 最初に、コードは オブジェクトのすべてのプロパティを持つ を取得 PropertyDescriptorCollection します。 その後、コードは から取得 MyProperty されます PropertyDescriptorCollection。 次に、このプロパティの属性を返し、属性変数に保存します。

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

// 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 リソース ファイルに保存します。 これらのリソース ファイルは、コードを変更せずにローカライズできます。

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

Note

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

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

コンストラクター

LocalizableAttribute(Boolean)

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

フィールド

Default

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

No

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

Yes

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

プロパティ

IsLocalizable

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

TypeId

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

(継承元 Attribute)

メソッド

Equals(Object)

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

GetHashCode()

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

GetType()

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

(継承元 Object)
IsDefaultAttribute()

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

IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
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)

適用対象

こちらもご覧ください