다음을 통해 공유


DesignerSerializationVisibilityAttribute 클래스

디자인 타임에 구성 요소에서 속성을 serialize할 때 사용할 지속성 형식을 지정합니다.

네임스페이스: System.ComponentModel
어셈블리: System(system.dll)

구문

‘선언
<AttributeUsageAttribute(AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Event)> _
Public NotInheritable Class DesignerSerializationVisibilityAttribute
    Inherits Attribute
‘사용 방법
Dim instance As DesignerSerializationVisibilityAttribute
[AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event)] 
public sealed class DesignerSerializationVisibilityAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Event)] 
public ref class DesignerSerializationVisibilityAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event) */ 
public final class DesignerSerializationVisibilityAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event) 
public final class DesignerSerializationVisibilityAttribute extends Attribute

설명

serializer가 디자인 모드 문서의 지속적인 상태를 유지하는 경우 디자인 타임에 설정된 속성 값을 유지하기 위해 구성 요소의 초기화 메서드에 코드를 추가하는 경우가 많습니다. 이 동작은 다른 동작에 대해 설정된 특성이 없는 경우 대부분의 기본 형식에 대해 기본적으로 수행됩니다.

DesignerSerializationVisibilityAttribute를 사용하면 속성 값이 Visible이고 초기화 코드에서 유지되는지, 아니면 Hidden이고 초기화 코드에서 유지되지 않는지, 아니면 Content로 이루어져 있고 개체의 숨겨지지 않은 각 공용 속성에 대해 생성된 초기화 코드가 해당 속성에 할당되어 있는지를 나타낼 수 있습니다.

DesignerSerializationVisibilityAttribute가 없는 멤버는 DesignerSerializationVisibilityAttributeVisible 값이 지정된 것으로 간주됩니다. Visible로 표시된 속성 값은 가능한 경우 형식에 대해 serializer로 serialize됩니다. 특정 형식 또는 속성에 사용자 지정 serialization을 지정하려면 DesignerSerializerAttribute를 사용합니다.

자세한 내용은 특성 개요특성을 사용하여 메타데이터 확장을 참조하십시오.

예제

다음 코드 예제에서는 Content로 설정된 DesignerSerializationVisibilityAttribute를 사용하는 방법을 보여 줍니다. 예제에서는 디자인 타임에 구성될 수 있는 사용자 컨트롤의 공용 속성 값을 유지합니다. 예제를 사용하려면 우선 다음 코드를 사용자 정의 컨트롤 라이브러리로 컴파일합니다. 그런 다음 새 Windows 응용 프로그램 프로젝트에서 컴파일된 .dll 파일에 대한 참조를 추가합니다. Visual Studio를 사용하는 경우 ContentSerializationExampleControl이 자동으로 도구 상자에 추가됩니다.

컨트롤을 도구 상자에서 폼으로 끌어 온 다음 속성 창에 표시된 DimensionData 개체의 속성을 설정합니다. 폼의 코드를 보면 코드가 부모 폼의 InitializeComponent 메서드에 추가된 것을 확인할 수 있습니다. 이 코드에서는 컨트롤의 속성 값을 디자인 모드에서 설정한 값으로 설정합니다.

Imports System
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 'New


        Protected Overloads Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub 'Dispose


        Private Sub InitializeComponent()
        End Sub 'InitializeComponent
    End Class 'ContentSerializationExampleControl

    ' 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 'New


        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 'DimensionData
End Namespace 'DesignerSerializationVisibilityTest
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
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 : System.Windows.Forms.UserControl
    {
    private System.ComponentModel.Container components = null;              
    
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public DimensionData Dimensions
    {
        get 
        {
        return new DimensionData(this);
        }       
    }

    public ContentSerializationExampleControl()
    {
            InitializeComponent();      
    }
        
    protected override void Dispose( bool disposing )
    {
        if( disposing )
        {
        if( components != null )
            components.Dispose();
        }
        base.Dispose( disposing );
    }

    private void InitializeComponent()
    {
        components = new System.ComponentModel.Container();
    }
    }

    [TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
    // This attribute indicates that the public properties of this object should be listed in the property grid.
    public class DimensionData
    {       
    private 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
        {
        return owner.Location;
        }
        set
        {
        owner.Location = value;
        }
    }

    public Size FormSize
    {
        get
            {
        return owner.Size;
        }
        set
        {
        owner.Size = value;
        }
    }
    }
}
#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;
   }
};
package DesignerSerializationVisibilityTest;

import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Windows.Forms.*;

// 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
   extends System.Windows.Forms.UserControl
{
    private System.ComponentModel.Container components = null;

    /** @attribute DesignerSerializationVisibility(
         DesignerSerializationVisibility.Content)
     */
    /** @property 
     */
    public DimensionData get_Dimensions()
    {
        return new DimensionData(this);
    } //get_Dimensions

    public ContentSerializationExampleControl()
    {
        InitializeComponent();
    } //ContentSerializationExampleControl

    protected void Dispose(boolean disposing)
    {
        if (disposing) {
            if (components != null) {
                components.Dispose();
            }
        }
        super.Dispose(disposing);
    } //Dispose

    private void InitializeComponent()
    {
        components = new System.ComponentModel.Container();
    } //InitializeComponent
} //ContentSerializationExampleControl

/** @attribute TypeConverterAttribute(System.ComponentModel.
     ExpandableObjectConverter.class)
 */
public class DimensionData
{
    // This attribute indicates that the public properties of this 
    // object should be listed in the property grid.
    private Control owner;

    // This class reads and writes the Location and Size properties 
    // from the Control which it is initialized to.
    DimensionData(Control owner)
    {
        this.owner = owner;
    } //DimensionData

    /** @property 
     */
    public Point get_Location()
    {
        return owner.get_Location();
    } //get_Location

    /** @property 
     */
    public void set_Location(Point value)
    {
        owner.set_Location(value);
    } //set_Location

    /** @property 
     */
    public Size get_FormSize()
    {
        return owner.get_Size();
    } //get_FormSize

    /** @property 
     */
    public void set_FormSize(Size value)
    {
        owner.set_Size(value);
    } //set_FormSize
} //DimensionData

상속 계층 구조

System.Object
   System.Attribute
    System.ComponentModel.DesignerSerializationVisibilityAttribute

스레드로부터의 안전성

이 형식의 모든 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.0, 1.1, 1.0에서 지원

참고 항목

참조

DesignerSerializationVisibilityAttribute 멤버
System.ComponentModel 네임스페이스
Attribute
PropertyDescriptor
AttributeCollection 클래스
PropertyDescriptorCollection

기타 리소스

방법: DesignerSerializationVisibilityAttribute가 있는 표준 형식 컬렉션 serialize