C # + arcengine serialization and deserialization of AE objects

Source: Internet
Author: User

During the AE development process, some objects must be temporarily stored, such as element, layer, map, and symbol. arcengine provides methods for serializing objects to save this information. All serializable objects support the ipersiststream interface (For details, refer to the help group documentation ). ixmlstream is also an important interface. for more information, see the help documentation.

 

This article is inspired by the technical documents of wall daniu.

Address: http://www.cnblogs.com/wall/archive/2009/02/26/1398447.html

 

Code
/// <Summary>
/// Serialize (serialize an object into an XML file)
/// </Summary>
/// <Param name = "xmlfile"> serialize the file path </param>
/// <Param name = "OBJ"> serialize an object </param>
/// <Returns> </returns>
Public static bool xmlserializer (string xmlfile, object OBJ)
{
Try
{
// Determine whether the ipersiststream interface is supported. Only objects that support this interface can be serialized.
If (obj is ESRI. ArcGIS. esrisystem. ipersiststream)
{
ESRI. ArcGIS. esrisystem. ipersiststream pstream = OBJ as ESRI. ArcGIS. esrisystem. ipersiststream;

ESRI. ArcGIS. esrisystem. ixmlstream xmlstream = new ESRI. ArcGIS. esrisystem. xmlstreamclass ();

Pstream. Save (xmlstream as ESRI. ArcGIS. esrisystem. istream, 0 );

Xmlstream. savetofile (xmlfile );

Return true;
}
Return false;
}
Catch (system. Exception E)
{
Return false;
}
}

--------------------------------------------------------------------------------

/// <Summary>
/// Deserialization (deserializing XML into a specified object)
/// </Summary>
/// <Param name = "xmlpathfile"> serialize a file </param>
/// <Param name = "OBJ"> serialize an object </param>
/// <Returns> </returns>
Public static bool xmldeserializer (string xmlpathfile, ref object OBJ)
{
Try
{
// Determine whether a file exists
If (system. Io. file. exists (xmlpathfile) & system. Io. Path. getextension (xmlpathfile) = ". xml ")
{
ESRI. ArcGIS. esrisystem. ipersiststream pstream = OBJ as ESRI. ArcGIS. esrisystem. ipersiststream;

ESRI. ArcGIS. esrisystem. ixmlstream xmlstream = new ESRI. ArcGIS. esrisystem. xmlstreamclass ();

Xmlstream. loadfromfile (xmlpathfile );
Pstream. Load (xmlstream as ESRI. ArcGIS. esrisystem. istream );

Return true;
}
Return false;
}
Catch (exception ex)
{
Return false;
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.