How to use CodeDomSerializer to serialize an object in .Net?
Posted
by user341127
on Stack Overflow
See other posts from Stack Overflow
or by user341127
Published on 2010-05-17T03:26:38Z
Indexed on
2010/05/17
3:30 UTC
Read the original article
Hit count: 420
I have a class, which is defined as the following:
[ToolboxItem(false)]
[DesignTimeVisible(false)]
[DesignerSerializer("DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer, DevExpress.XtraEditors.v10.1.Design", "System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design")]
[Designer("DevExpress.XtraEditors.Design.BaseRepositoryItemDesigner, DevExpress.XtraEditors.v10.1.Design")]
[LicenseProvider(typeof(DXEditorLicenseProvider))]
public class RepositoryItem : Component, ISupportInitialize, ICustomTypeDescriptor, IImageCollectionHelper
{......}
I tried the following code to serialize the object of this class.
DesignerSerializationManager m = new System.ComponentModel.Design.Serialization.DesignerSerializationManager();
m.CreateSession();
DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer s = m.GetSerializer(typeof(RepositoryItem), typeof(DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer)) as DevExpress.XtraEditors.Design.RepositoryItemCodeDomSerializer;
RepositoryItem i = persistentRepository1.Items[0];
//m.Container.Add(i);
s.Serialize(m,i );// An error "Object reference not set to an instance of an object." happended here.
For I am not familiar with CodeDom, I have spent one day to get the way out. I guess the above code has some stupid mistakes. Please give me a hand to show how to serialize AND DeSelialize such objects of the class of Repository.
BTW, the reason I don't use any other serializer is that I am supposed not to have rights to know the source code of RepositoryItem and others could inherit RepositoryItem at the same time. And actually I have to deal with RepositoryItem and its descendants.
Thank you in advance.
Ying
© Stack Overflow or respective owner