DesignerSerializationVisibilityAttribute クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
デザイン時にコンポーネントのプロパティをシリアル化するときに使用する永続化の種類を指定します。
public ref class DesignerSerializationVisibilityAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class DesignerSerializationVisibilityAttribute : Attribute
public sealed class DesignerSerializationVisibilityAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)]
public sealed class DesignerSerializationVisibilityAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property)>]
type DesignerSerializationVisibilityAttribute = class
inherit Attribute
type DesignerSerializationVisibilityAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Method | System.AttributeTargets.Property)>]
type DesignerSerializationVisibilityAttribute = class
inherit Attribute
Public NotInheritable Class DesignerSerializationVisibilityAttribute
Inherits Attribute
- 継承
- 属性
例
次のコード例は、Contentに設定されたDesignerSerializationVisibilityAttributeの使用を示しています。 ユーザー コントロールのパブリック プロパティの値が保持され、デザイン時に構成できます。 この例を使用するには、まず次のコードをユーザー コントロール ライブラリにコンパイルします。 次に、コンパイルされた .dll ファイルへの参照を新しい Windows アプリケーション プロジェクトに追加します。 Visual Studioを使用している場合、ContentSerializationExampleControlは自動的に Toolbox に追加されます。
コントロールを Toolbox からフォームにドラッグし、プロパティ ウィンドウに一覧表示されている DimensionData オブジェクトのプロパティを設定します。 フォームのコードを表示すると、親フォームの InitializeComponent メソッドにコードが追加されます。 このコードでは、コントロールのプロパティの値を、デザイン モードで設定した値に設定します。
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Windows::Forms;
// This attribute indicates that the public properties of this object should be listed in the property grid.
[TypeConverterAttribute(System::ComponentModel::ExpandableObjectConverter::typeid)]
public ref class DimensionData
{
private:
Control^ owner;
internal:
// This class reads and writes the Location and Size properties from the Control which it is initialized to.
DimensionData( Control^ owner )
{
this->owner = owner;
}
public:
property Point Location
{
Point get()
{
return owner->Location;
}
void set( Point value )
{
owner->Location = value;
}
}
property Size FormSize
{
Size get()
{
return owner->Size;
}
void set( Size value )
{
owner->Size = value;
}
}
};
// The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility
// attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized.
// The public, not hidden properties of the object that are set at design time will be persisted in the initialization code
// for the class object. Content persistence will not work for structs without a custom TypeConverter.
public ref class ContentSerializationExampleControl: public System::Windows::Forms::UserControl
{
private:
System::ComponentModel::Container^ components;
public:
property DimensionData^ Dimensions
{
[DesignerSerializationVisibility(DesignerSerializationVisibility::Content)]
DimensionData^ get()
{
return gcnew DimensionData( this );
}
}
ContentSerializationExampleControl()
{
InitializeComponent();
}
public:
~ContentSerializationExampleControl()
{
if ( components != nullptr )
{
delete components;
}
}
private:
void InitializeComponent()
{
components = gcnew System::ComponentModel::Container;
}
};
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace DesignerSerializationVisibilityTest;
// The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility
// attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized.
// The public, not hidden properties of the object that are set at design time will be persisted in the initialization code
// for the class object. Content persistence will not work for structs without a custom TypeConverter.
public class ContentSerializationExampleControl : UserControl
{
Container components;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DimensionData Dimensions => new(this);
public ContentSerializationExampleControl() => InitializeComponent();
protected override void Dispose(bool disposing)
{
if (disposing)
{
components?.Dispose();
}
base.Dispose(disposing);
}
void InitializeComponent() => components = new Container();
}
[TypeConverter(typeof(ExpandableObjectConverter))]
// This attribute indicates that the public properties of this object should be listed in the property grid.
public class DimensionData
{
readonly Control owner;
// This class reads and writes the Location and Size properties from the Control which it is initialized to.
internal DimensionData(Control owner) => this.owner = owner;
public Point Location
{
get => owner.Location;
set => owner.Location = value;
}
public Size FormSize
{
get => owner.Size;
set => owner.Size = value;
}
}
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Windows.Forms
Namespace DesignerSerializationVisibilityTest
_
' The code for this user control declares a public property of type DimensionData with a DesignerSerializationVisibility
' attribute set to DesignerSerializationVisibility.Content, indicating that the properties of the object should be serialized.
' The public, not hidden properties of the object that are set at design time will be persisted in the initialization code
' for the class object. Content persistence will not work for structs without a custom TypeConverter.
Public Class ContentSerializationExampleControl
Inherits System.Windows.Forms.UserControl
Private components As System.ComponentModel.Container = Nothing
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property Dimensions() As DimensionData
Get
Return New DimensionData(Me)
End Get
End Property
Public Sub New()
InitializeComponent()
End Sub
Protected Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If (components IsNot Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private Sub InitializeComponent()
End Sub
End Class
' This attribute indicates that the public properties of this object should be listed in the property grid.
<TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))> _
Public Class DimensionData
Private owner As Control
' This class reads and writes the Location and Size properties from the Control which it is initialized to.
Friend Sub New(ByVal owner As Control)
Me.owner = owner
End Sub
Public Property Location() As Point
Get
Return owner.Location
End Get
Set(ByVal Value As Point)
owner.Location = Value
End Set
End Property
Public Property FormSize() As Size
Get
Return owner.Size
End Get
Set(ByVal Value As Size)
owner.Size = Value
End Set
End Property
End Class
End Namespace 'DesignerSerializationVisibilityTest
注釈
シリアライザーは、デザイン モード ドキュメントの永続化可能な状態を保持する場合、多くの場合、デザイン時に設定されたプロパティの値を保持するコードをコンポーネントの初期化メソッドに追加します。 これは、他の動作を指示する属性が設定されていない場合、ほとんどの基本型で既定で発生します。
DesignerSerializationVisibilityAttributeを使用すると、プロパティの値がVisibleであり、初期化コード、Hiddenで永続化する必要があるかどうか、または初期化コードで永続化しないか、プロパティに割り当てられたオブジェクトの非表示のプロパティではなく、パブリックごとに初期化コードを生成する必要があるContentで構成されているかどうかを示すことができます。
DesignerSerializationVisibilityAttributeを持たないメンバーは、値が Visible のDesignerSerializationVisibilityAttributeがあるかのように扱われます。 Visibleとしてマークされたプロパティの値は、可能であれば、型のシリアライザーによってシリアル化されます。 特定の型またはプロパティのカスタム シリアル化を指定するには、 DesignerSerializerAttributeを使用します。
詳細については、「属性」を参照してください。
コンストラクター
| 名前 | 説明 |
|---|---|
| DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility) |
指定したDesignerSerializationVisibilityAttribute値を使用して、DesignerSerializationVisibility クラスの新しいインスタンスを初期化します。 |
フィールド
| 名前 | 説明 |
|---|---|
| Content |
シリアライザーがプロパティ自体ではなく、プロパティの内容をシリアル化する必要があることを指定します。 このフィールドは読み取り専用です。 |
| Default |
既定値 ( Visible) を指定します。つまり、ビジュアル デザイナーは既定のルールを使用してプロパティの値を生成します。 この |
| Hidden |
シリアライザーがプロパティの値をシリアル化しないように指定します。 この |
| Visible |
シリアライザーがプロパティの値をシリアル化できるようにする必要があることを指定します。 この |
プロパティ
| 名前 | 説明 |
|---|---|
| TypeId |
派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。 (継承元 Attribute) |
| Visibility |
プロパティの値を保持するかどうかを決定するときにシリアライザーが使用する必要がある基本的なシリアル化モードを示す値を取得します。 |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
このインスタンスと指定したオブジェクトが等しいかどうかを示します。 |
| 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) |