本文整理汇总了C#中System.ComponentModel.Design.Serialization.IDesignerSerializationManager接口的典型用法代码示例。如果您正苦于以下问题:C# IDesignerSerializationManager接口的具体用法?C# IDesignerSerializationManager怎么用?C# IDesignerSerializationManager使用的例子?那么恭喜您, 这里精选的接口代码示例或许可以为您提供帮助。
IDesignerSerializationManager接口属于System.ComponentModel.Design.Serialization命名空间,在下文中一共展示了IDesignerSerializationManager接口的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
//引入命名空间
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;
}
}
}
}
开发者ID:.NET开发者,项目名称:System.ComponentModel.Design.Serialization,代码行数:57,代码来源:IDesignerSerializationManager