DesignOnlyAttributeとは何? わかりやすく解説 Weblio辞書 (original) (raw)

プロパティ設定できるのがデザイン時だけかどうか指定します

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

Visual Basic (宣言)

<AttributeUsageAttribute(AttributeTargets.All)> _ Public NotInheritable Class DesignOnlyAttribute Inherits Attribute

Visual Basic (使用法)

Dim instance As DesignOnlyAttribute

C#

[AttributeUsageAttribute(AttributeTargets.All)] public sealed class DesignOnlyAttribute : Attribute

C++

[AttributeUsageAttribute(AttributeTargets::All)] public ref class DesignOnlyAttribute sealed : public Attribute

J#

/** @attribute AttributeUsageAttribute(AttributeTargets.All) */ public final class DesignOnlyAttribute extends Attribute

JScript

AttributeUsageAttribute(AttributeTargets.All) public final class DesignOnlyAttribute extends Attribute

解説解説

DesignOnlyAttributetrue設定してマークされているメンバは、デザイン時にだけ設定できます通常、これらのプロパティデザイン時しか存在せず実行時オブジェクト上に存在するプロパティには対応しません。

属性持たないメンバ、または DesignOnlyAttributefalse設定してマークされているメンバは、実行時設定できます既定値false です。

DesignOnlyAttributetrue設定されているプロパティは、値が InitializeComponent メソッドではなく .resx ファイルシリアル化されます

詳細については、属性概要属性使用したメタデータ拡張 の各トピック参照してください

使用例使用例

GetLanguage プロパティ作成する例を次に示します。このプロパティは、DesignOnlyAttributeマークされます。

Visual Basic

<DesignOnly(True)> _ Public Property GetLanguage() As CultureInfo Get ' Insert code here. Return myCultureInfo End Get Set ' Insert code here. End Set End Property

C#

[DesignOnly(true)] public CultureInfo GetLanguage { get { // Insert code here. return myCultureInfo; } set { // Insert code here. } }

C++

public: [DesignOnly(true)] property CultureInfo^ GetLanguage { CultureInfo^ get() { // Insert code here. return myCultureInfo; } void set( CultureInfo^ value ) { // Insert code here. } }

J#

/** @attribute DesignOnly(true) / /* @property */ public CultureInfo get_GetLanguage() { // Insert code here. return myCultureInfo; } //get_GetLanguage

/** @property */ public void set_GetLanguage(CultureInfo value) { // Insert code here. } //set_GetLanguage

DesignOnlyAttribute の値を取得する例を次に示します最初にオブジェクトすべてのプロパティ保持する PropertyDescriptorCollection を取得します次にインデックス付けて PropertyDescriptorCollection から GetLanguage プロパティ検索します。そして、このプロパティ属性返し、その属性属性変数保存します

最後に、AttributeCollection から DesignOnlyAttribute取得し取得した情報コンソール画面書き込むことによって、プロパティ設定できるのがデザイン時だけかどうか出力します

Visual Basic

' Gets the attributes for the property. Dim attributes As AttributeCollection = _ TypeDescriptor.GetProperties(Me)("GetLanguage").Attributes

' Prints the description by retrieving the DescriptionAttribute ' from the AttributeCollection. Dim myAttribute As DesignOnlyAttribute = _ CType(attributes(GetType(DesignOnlyAttribute)), DesignOnlyAttribute) Console.WriteLine(("This property is design only :" & _ myAttribute.IsDesignOnly.ToString()))

C#

// Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this)["GetLanguage"].Attributes;

/* Prints the description by retrieving the DescriptionAttribute

C++

// Gets the attributes for the property. AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "GetLanguage" ]->Attributes;

/* Prints the description by retrieving the DescriptionAttribute * from the AttributeCollection. */ DesignOnlyAttribute^ myAttribute = dynamic_cast<DesignOnlyAttribute^>(attributes[ DesignOnlyAttribute::typeid ]); Console::WriteLine( "This property is design only :{0}", myAttribute->IsDesignOnly );

J#

// Gets the attributes for the property. AttributeCollection attributes = TypeDescriptor.GetProperties(this). get_Item("GetLanguage").get_Attributes();

/* Prints the description by retrieving the DescriptionAttribute from the AttributeCollection. */ DesignOnlyAttribute myAttribute = (DesignOnlyAttribute)(attributes. get_Item(DesignOnlyAttribute.class.ToType()));

Console.WriteLine("This property is design only :" + System.Convert.ToString(myAttribute.get_IsDesignOnly()));

継承階層継承階層

System.Object
System.Attribute
System.ComponentModel.DesignOnlyAttribute

スレッド セーフスレッド セーフ

この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。

プラットフォームプラットフォーム

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォーム中には.NET Framework によってサポートされていないバージョンありますサポートされているバージョンについては、「システム要件」を参照してください

バージョン情報バージョン情報

.NET Framework
サポート対象 : 2.01.11.0

参照参照

関連項目
DesignOnlyAttribute メンバ
System.ComponentModel 名前空間
Attribute
PropertyDescriptor

DesignOnlyAttribute クラス新しインスタンス初期化します。

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

Visual Basic (宣言)

Public Sub New ( _ isDesignOnly As Boolean _ )

Visual Basic (使用法)

Dim isDesignOnly As Boolean

Dim instance As New DesignOnlyAttribute(isDesignOnly)

C#

public DesignOnlyAttribute ( bool isDesignOnly )

C++

public: DesignOnlyAttribute ( bool isDesignOnly )

J#

public DesignOnlyAttribute ( boolean isDesignOnly )

JScript

public function DesignOnlyAttribute ( isDesignOnly : boolean )

パラメータ

isDesignOnly

プロパティ設定できるのがデザイン時だけの場合は **true**。プロパティデザイン時と実行時両方設定できる場合は **false**。

プラットフォームプラットフォーム

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォーム中には.NET Framework によってサポートされていないバージョンありますサポートされているバージョンについては、「システム要件」を参照してください

バージョン情報バージョン情報

.NET Framework
サポート対象 : 2.01.11.0

参照参照

関連項目
DesignOnlyAttribute クラス
DesignOnlyAttribute メンバ
System.ComponentModel 名前空間