.NET Framework Class Library
DesignerSerializationVisibilityAttribute Class

Specifies the type of persistence to use when serializing a property on a component at design time.

Inheritance Hierarchy
SystemObject
   SystemAttribute
    System.ComponentModelDesignerSerializationVisibilityAttribute

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)
Syntax
<[%$TOPIC/zdx44zck_en-us_VS_110_2_0_0_0_0%]([%$TOPIC/zdx44zck_en-us_VS_110_2_0_0_0_1%].Method Or [%$TOPIC/zdx44zck_en-us_VS_110_2_0_0_0_2%].Property Or [%$TOPIC/zdx44zck_en-us_VS_110_2_0_0_0_3%].Field Or [%$TOPIC/zdx44zck_en-us_VS_110_2_0_0_0_4%].Event)> _
Public NotInheritable Class DesignerSerializationVisibilityAttribute _
	Inherits [%$TOPIC/zdx44zck_en-us_VS_110_2_0_0_0_5%]
[[%$TOPIC/zdx44zck_en-us_VS_110_2_0_1_0_0%]([%$TOPIC/zdx44zck_en-us_VS_110_2_0_1_0_1%].Method|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_1_0_2%].Property|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_1_0_3%].Field|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_1_0_4%].Event)]
public sealed class DesignerSerializationVisibilityAttribute : [%$TOPIC/zdx44zck_en-us_VS_110_2_0_1_0_5%]
[[%$TOPIC/zdx44zck_en-us_VS_110_2_0_2_0_0%]([%$TOPIC/zdx44zck_en-us_VS_110_2_0_2_0_1%]::Method|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_2_0_2%]::Property|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_2_0_3%]::Field|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_2_0_4%]::Event)]
public ref class DesignerSerializationVisibilityAttribute sealed : public [%$TOPIC/zdx44zck_en-us_VS_110_2_0_2_0_5%]
[<[%$TOPIC/zdx44zck_en-us_VS_110_2_0_3_0_0%]>]
[<[%$TOPIC/zdx44zck_en-us_VS_110_2_0_3_0_1%]([%$TOPIC/zdx44zck_en-us_VS_110_2_0_3_0_2%].Method|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_3_0_3%].Property|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_3_0_4%].Field|[%$TOPIC/zdx44zck_en-us_VS_110_2_0_3_0_5%].Event)>]
type DesignerSerializationVisibilityAttribute =  
    class 
        inherit [%$TOPIC/zdx44zck_en-us_VS_110_2_0_3_0_6%] 
    end

The DesignerSerializationVisibilityAttribute type exposes the following members.

Constructors
  NameDescription
Public method DesignerSerializationVisibilityAttributeInitializes a new instance of the DesignerSerializationVisibilityAttribute class using the specified DesignerSerializationVisibility value.
Top
Properties
  NameDescription
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Public property VisibilityGets a value indicating the basic serialization mode a serializer should use when determining whether and how to persist the value of a property.
Top
Methods
  NameDescription
Public method EqualsIndicates whether this instance and a specified object are equal. (Overrides AttributeEquals(Object).)
Public method GetHashCodeReturns the hash code for this object. (Overrides AttributeGetHashCode.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeGets a value indicating whether the current value of the attribute is the default value for the attribute. (Overrides AttributeIsDefaultAttribute.)
Public method MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Fields
  NameDescription
Public field Static member ContentSpecifies that a serializer should serialize the contents of the property, rather than the property itself. This field is read-only.
Public field Static member DefaultSpecifies the default value, which is Visible, that is, a visual designer uses default rules to generate the value of a property. This static field is read-only.
Public field Static member HiddenSpecifies that a serializer should not serialize the value of the property. This static field is read-only.
Public field Static member VisibleSpecifies that a serializer should be allowed to serialize the value of the property. This static field is read-only.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top
Remarks

When a serializer persists the persistable state of a design mode document, it often adds code to the initialization method of components to persist values of properties that have been set at design time. This happens by default for most basic types, if no attribute has been set to direct other behavior.

With the DesignerSerializationVisibilityAttribute, you can indicate whether the value for a property is Visible, and should be persisted in initialization code, Hidden, and should not be persisted in initialization code, or consists of Content, which should have initialization code generated for each public, not hidden property of the object assigned to the property.

Members that do not have a DesignerSerializationVisibilityAttribute will be treated as though they have a DesignerSerializationVisibilityAttribute with a value of Visible. The values of a property marked as Visible will be serialized, if possible, by a serializer for the type. To specify custom serialization for a particular type or property, use the DesignerSerializerAttribute.

For more information, see Extending Metadata Using Attributes.

Examples

The following code example demonstrates the use of a DesignerSerializationVisibilityAttribute set to Content. It persists the values of a public property of a user control, which can be configured at design time. To use the example, first compile the following code into a user control library. Next, add a reference to the compiled .dll file in a new Windows Application project. If you are using Visual Studio, the ContentSerializationExampleControl is automatically added to the Toolbox.

Drag the control from the Toolbox to a form, and set the properties of the DimensionData object listed in the Properties window. When you view the code for the form, code will have been added to the InitializeComponent method of the parent form. This code sets the values of the control's properties to those which you have set in design mode.

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 (components IsNot 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;
   }
};
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.