IDesignerSerializationManager 介面
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供可以管理設計階段序列化 (Serialization) 的介面。
public interface class IDesignerSerializationManager : IServiceProvider
public interface IDesignerSerializationManager : IServiceProvider
type IDesignerSerializationManager = interface
interface IServiceProvider
Public Interface IDesignerSerializationManager
Implements IServiceProvider
- 衍生
- 實作
範例
下列範例說明如何使用 IDesignerSerializationManager 來串行化和還原串行化Code DOM語句。
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Design.dll>
using namespace System;
using namespace System::CodeDom;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::ComponentModel::Design::Serialization;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace CodeDomSerializerSample
{
ref class MyComponent;
private ref class MyCodeDomSerializer: public CodeDomSerializer
{
public:
Object^ Deserialize( IDesignerSerializationManager^ manager, Object^ codeObject ) new
{
// This is how we associate the component with the serializer.
CodeDomSerializer^ baseClassSerializer = (CodeDomSerializer^)(
manager->GetSerializer(
MyComponent::typeid->BaseType, CodeDomSerializer::typeid ));
/* This is the simplest case, in which the class just calls the base class
to do the work. */
return baseClassSerializer->Deserialize( manager, codeObject );
}
Object^ Serialize( IDesignerSerializationManager^ manager, Object^ value ) new
{
/* Associate the component with the serializer in the same manner as with
Deserialize */
CodeDomSerializer^ baseClassSerializer = (CodeDomSerializer^)(
manager->GetSerializer(
MyComponent::typeid->BaseType, CodeDomSerializer::typeid ));
Object^ codeObject = baseClassSerializer->Serialize( manager, value );
/* Anything could be in the codeObject. This sample operates on a
CodeStatementCollection. */
if ( (CodeStatementCollection^)(codeObject) )
{
CodeStatementCollection^ statements = (CodeStatementCollection^)(codeObject);
// The code statement collection is valid, so add a comment.
String^ commentText = "This comment was added to this object by a custom serializer.";
CodeCommentStatement^ comment = gcnew CodeCommentStatement( commentText );
statements->Insert( 0, comment );
}
return codeObject;
}
};
[DesignerSerializer(CodeDomSerializerSample::MyCodeDomSerializer::typeid,
CodeDomSerializer::typeid)]
public ref class MyComponent: public Component
{
private:
String^ localProperty;
public:
MyComponent()
{
localProperty = "Component Property Value";
}
property String^ LocalProperty
{
String^ get()
{
return localProperty;
}
void set( String^ value )
{
localProperty = value;
}
}
};
}
using System;
using System.CodeDom;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Drawing;
using System.Windows.Forms;
namespace CodeDomSerializerSample
{
internal class MyCodeDomSerializer : CodeDomSerializer {
public override object Deserialize(IDesignerSerializationManager manager, object codeObject) {
// This is how we associate the component with the serializer.
CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.
GetSerializer(typeof(MyComponent).BaseType, typeof(CodeDomSerializer));
/* This is the simplest case, in which the class just calls the base class
to do the work. */
return baseClassSerializer.Deserialize(manager, codeObject);
}
public override object Serialize(IDesignerSerializationManager manager, object value) {
/* Associate the component with the serializer in the same manner as with
Deserialize */
CodeDomSerializer baseClassSerializer = (CodeDomSerializer)manager.
GetSerializer(typeof(MyComponent).BaseType, typeof(CodeDomSerializer));
object codeObject = baseClassSerializer.Serialize(manager, value);
/* Anything could be in the codeObject. This sample operates on a
CodeStatementCollection. */
if (codeObject is CodeStatementCollection) {
CodeStatementCollection statements = (CodeStatementCollection)codeObject;
// The code statement collection is valid, so add a comment.
string commentText = "This comment was added to this object by a custom serializer.";
CodeCommentStatement comment = new CodeCommentStatement(commentText);
statements.Insert(0, comment);
}
return codeObject;
}
}
[DesignerSerializer(typeof(MyCodeDomSerializer), typeof(CodeDomSerializer))]
public class MyComponent : Component {
private string localProperty = "Component Property Value";
public string LocalProperty {
get {
return localProperty;
}
set {
localProperty = value;
}
}
}
}
Imports System.CodeDom
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.Serialization
Imports System.Drawing
Imports System.Windows.Forms
Namespace CodeDomSerializerSample
Friend Class MyCodeDomSerializer
Inherits CodeDomSerializer
Public Overrides Function Deserialize(ByVal manager As IDesignerSerializationManager, _
ByVal codeObject As Object) As Object
' This is how we associate the component with the serializer.
Dim baseClassSerializer As CodeDomSerializer = CType(manager.GetSerializer( _
GetType(MyComponent).BaseType, GetType(CodeDomSerializer)), CodeDomSerializer)
' This is the simplest case, in which the class just calls the base class
' to do the work.
Return baseClassSerializer.Deserialize(manager, codeObject)
End Function 'Deserialize
Public Overrides Function Serialize(ByVal manager As IDesignerSerializationManager, _
ByVal value As Object) As Object
' Associate the component with the serializer in the same manner as with
' Deserialize
Dim baseClassSerializer As CodeDomSerializer = CType(manager.GetSerializer( _
GetType(MyComponent).BaseType, GetType(CodeDomSerializer)), CodeDomSerializer)
Dim codeObject As Object = baseClassSerializer.Serialize(manager, value)
' Anything could be in the codeObject. This sample operates on a
' CodeStatementCollection.
If TypeOf codeObject Is CodeStatementCollection Then
Dim statements As CodeStatementCollection = CType(codeObject, CodeStatementCollection)
' The code statement collection is valid, so add a comment.
Dim commentText As String = "This comment was added to this object by a custom serializer."
Dim comment As New CodeCommentStatement(commentText)
statements.Insert(0, comment)
End If
Return codeObject
End Function 'Serialize
End Class
<DesignerSerializer(GetType(MyCodeDomSerializer), GetType(CodeDomSerializer))> _
Public Class MyComponent
Inherits Component
Private localProperty As String = "Component Property Value"
Public Property LocalProp() As String
Get
Return localProperty
End Get
Set(ByVal Value As String)
localProperty = Value
End Set
End Property
End Class
End Namespace
備註
設計工具可以利用 IDesignerSerializationManager 來存取服務,以便管理設計時間串行化程式。 例如,實作設計工具串行化管理員的類別可以使用這個介面來建立物件、查閱類型、識別物件,以及自定義特定類型的串行化。
屬性
Context |
取得以堆疊為基礎、使用者定義的儲存區,這個區域對於序列化程式之間的通訊很有用。 |
Properties |
指示可使用可用的序列化工具序列化的自訂屬性。 |
方法
AddSerializationProvider(IDesignerSerializationProvider) |
將指定的序列化提供者加入序列化管理員。 |
CreateInstance(Type, ICollection, String, Boolean) |
建立指定型別的執行個體,並將它加入具名執行個體的集合。 |
GetInstance(String) |
取得以指定的名稱建立的物件的執行個體,或 |
GetName(Object) |
取得指定物件的名稱,或 |
GetSerializer(Type, Type) |
為指定的物件型別取得要求的型別的序列化工具。 |
GetService(Type) |
取得指定類型的服務物件。 (繼承來源 IServiceProvider) |
GetType(String) |
取得指定名稱的型別。 |
RemoveSerializationProvider(IDesignerSerializationProvider) |
將自訂的序列化提供者從序列化管理員移除。 |
ReportError(Object) |
報告序列化中的錯誤。 |
SetName(Object, String) |
設定指定的現有物件的名稱。 |
事件
ResolveName |
於 GetName(Object) 無法在序列化管理員的名稱表格中找到指定的名稱時發生。 |
SerializationComplete |
於序列化完成時發生。 |