DesignerSerializationVisibilityAttribute Kelas

Definisi

Menentukan jenis persistensi yang akan digunakan saat menserialisasikan properti pada komponen pada waktu desain.

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
Warisan
DesignerSerializationVisibilityAttribute
Atribut

Contoh

Contoh kode berikut menunjukkan penggunaan set DesignerSerializationVisibilityAttribute ke Content. Ini mempertahankan nilai properti publik kontrol pengguna, yang dapat dikonfigurasi pada waktu desain. Untuk menggunakan contoh, pertama-tama kompilasi kode berikut ke dalam pustaka kontrol pengguna. Selanjutnya, tambahkan referensi ke file .dll yang dikompilasi dalam proyek Aplikasi Windows baru. Jika Anda menggunakan Visual Studio, ContentSerializationExampleControl secara otomatis ditambahkan ke Kotak Alat.

Seret kontrol dari Kotak Alat ke formulir, dan atur properti objek yang DimensionData tercantum di jendela Properti. Saat Anda melihat kode untuk formulir, kode akan ditambahkan ke InitializeComponent metode formulir induk. Kode ini mengatur nilai properti kontrol ke yang telah Anda tetapkan dalam mode desain.

#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;
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;
        }
    }
    }
}
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

Keterangan

Ketika serializer mempertahankan status persistable dari dokumen mode desain, itu sering menambahkan kode ke metode inisialisasi komponen untuk mempertahankan nilai properti yang telah diatur pada waktu desain. Ini terjadi secara default untuk sebagian besar jenis dasar, jika tidak ada atribut yang diatur untuk mengarahkan perilaku lain.

DesignerSerializationVisibilityAttributeDengan , Anda dapat menunjukkan apakah nilai untuk properti adalah Visible, dan harus dipertahankan dalam kode inisialisasi, Hidden, dan tidak boleh dipertahankan dalam kode inisialisasi, atau terdiri dari , yang seharusnya memiliki kode inisialisasi Contentyang dihasilkan untuk setiap publik, bukan properti tersembunyi dari objek yang ditetapkan ke properti .

Anggota yang tidak memiliki DesignerSerializationVisibilityAttribute akan diperlakukan seolah-olah mereka memiliki DesignerSerializationVisibilityAttribute dengan nilai Visible. Nilai properti yang ditandai sebagai Visible akan diserialisasikan, jika memungkinkan, oleh serializer untuk jenis tersebut. Untuk menentukan serialisasi kustom untuk jenis atau properti tertentu, gunakan DesignerSerializerAttribute.

Untuk informasi selengkapnya, lihat Atribut.

Konstruktor

DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility)

Menginisialisasi instans DesignerSerializationVisibilityAttribute baru kelas menggunakan nilai yang ditentukan DesignerSerializationVisibility .

Bidang

Content

Menentukan bahwa serializer harus membuat serialisasi konten properti, bukan properti itu sendiri. Bidang ini hanya-baca.

Default

Menentukan nilai default, yaitu Visible, yaitu, desainer visual menggunakan aturan default untuk menghasilkan nilai properti. Bidang ini static bersifat baca-saja.

Hidden

Menentukan bahwa serializer tidak boleh membuat serialisasi nilai properti. Bidang ini static bersifat baca-saja.

Visible

Menentukan bahwa serializer harus diizinkan untuk membuat serialisasi nilai properti. Bidang ini static bersifat baca-saja.

Properti

TypeId

Ketika diimplementasikan di kelas turunan, mendapatkan pengidentifikasi unik untuk ini Attribute.

(Diperoleh dari Attribute)
Visibility

Mendapatkan nilai yang menunjukkan mode serialisasi dasar yang harus digunakan serializer saat menentukan apakah dan cara mempertahankan nilai properti.

Metode

Equals(Object)

Menunjukkan apakah instans ini dan objek tertentu sama.

GetHashCode()

Mengembalikan kode hash untuk objek ini.

GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Mendapatkan nilai yang menunjukkan apakah nilai atribut saat ini adalah nilai default untuk atribut .

IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga