http://www.cnblogs.com/jindin/archive/2009/07/23/1529695.html

在AE开发过程,总是要将某些对象暂时存储起来,像element,layer,map,symbol 等等. ArcEngine提供了序列化对象的方法来保存这些信息, 所有能序列化的对象都支持IPersistStream 接口(详查帮组文档) .此外IXMLStream 也是比较重要的接口.具体请查看帮助文档.

/// <summary>
        /// 序列化(将对象序列化成xml文件)
        /// </summary>
        /// <param name="xmlfile">序列化文件路径</param>
        /// <param name="obj">序列化对象</param>
        /// <returns></returns>
        public static bool xmlSerializer(string xmlfile,object obj)
        {
            try
            {
                //判断是否支持IPersistStream接口,只有支持该接口的对象才能进行序列化
                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>
        /// 反序列化(将xml反序列化成指定的对象)
        /// </summary>
        /// <param name="xmlPathFile">序列化文件</param>
        /// <param name="obj">序列化对象</param>
        /// <returns></returns>
        public static bool XmlDeSerializer(string xmlPathFile,ref object obj)        
        {    
            try
            {
                //判断文件是否存在
                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;
            }
        }

C#+ArcEngine 序列化和反序列化AE对象的更多相关文章

  1. C#序列化及反序列化Json对象通用类JsonHelper

    当今的程序界Json大行其道.因为Json对象具有简短高效等优势,广受广大C#码农喜爱.这里发一个序列化及反序列化Json对象通用类库,希望对大家有用. public class JsonHelper ...

  2. Java IO详解(六)------序列化与反序列化(对象流)

    File 类的介绍:http://www.cnblogs.com/ysocean/p/6851878.html Java IO 流的分类介绍:http://www.cnblogs.com/ysocea ...

  3. 在MVC中使用Json.Net序列化和反序列化Json对象

    在.Net的MVC开发中,经常会使用到Json对象,于是,系统提供了JsonResult这个对象,其本质是调用.Net系统自带的Json序列化类JavaScriptSerializer对数据对象进行序 ...

  4. Fastjson 序列化,反序列化Map对象排序问题(字符串转map,map转字符串)

    背景 记录项目中遇到的 关于fastjson jsonobject转string乱序,string转jsonObject乱序问题的解决方案 fastJson issues 问题来源描述参见: http ...

  5. xml序列化及反序列化.net对象

    序列化一个类通常添加[XmlRoot("根节点名字")] 找到要序列化的内容 对要序列化的类添加 [Serializable]属性用于序列化 对于要序列化的字段添加  [XmlEl ...

  6. Json.NET序列化后包含类型,保证序列化和反序列化的对象类型相同(转载)

    This sample uses the TypeNameHandlingsetting to include type information when serializing JSON and r ...

  7. fastjson 序列化,反序列化Map对象的顺序问题

    使用JSONObject  读取JSON字符串时,读取出来的数据,通过变量时是无序的. 但是业务希望返回是顺序的. String str="{name:\"A\",add ...

  8. 25_java之Properities集合|对象序列化和反序列化

    01Properties集合的特点 * A: Properties集合的特点 * a: Properties类介绍 * Properties 类表示了一个持久的属性集.Properties 可保存在流 ...

  9. Python开发基础-Day19继承组合应用、对象序列化和反序列化,选课系统综合示例

    继承+组合应用示例 class Date: #定义时间类,包含姓名.年.月.日,用于返回生日 def __init__(self,name,year,mon,day): self.name = nam ...

随机推荐

  1. 转载LINQ TO Entity 在数据库发生更改时更新实体数据模型 .edmx 文件

    转载原出处:http://blog.csdn.net/litao2/article/details/8629335 在“模型浏览器”中,右击 .edmx 文件,然后选择“从数据库更新模型”. 模型更新 ...

  2. CC_CALLBACK原理及应用

    http://my.oschina.net/u/555701/blog/219844 c++ 11 基础 :     std::function 类模版 std::function是一种通用.多态的函 ...

  3. C#- 将秒数转化成任意时间格式

    将秒数转化成任意时间格式,可以使用C#的一个函数TimeSpan,看示例: TimeSpan ts = new TimeSpan(0, 0, 3661); richTextBox2.Text = ts ...

  4. ASP.NET- 查找Repeater控件中嵌套的控件

    如何在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件?在Repeater的ItemTemplate模板中的控件,我们可以用Items属性来遍历行并用Find ...

  5. 强烈推荐android studio用的几个插件,androidstudio

    不懂安装studio插件,看参考博文:android stuido插件安装:http://blog.csdn.net/liang5630/article/details/46372447 1.Butt ...

  6. 修改 suse 上的postfix 的日志路径

    刚刚搭建的邮件服务器,没过多久硬盘就爆满了,不得已移动存储,包括日志. 移动存储灰常简单,查找 /etc/postfix/main.cf 中的 data_directory / base_direct ...

  7. Scribefire发CSDN博客

    历史 在非常久非常久曾经,CSDN是支持外部工具来写文章的,但是在还有一个非常久非常久曾经就不行了. 突然看到CSDN有能够用外部工具来写博客了(CSDN的公告),一直以来都纠结这个问题,CSDN的编 ...

  8. 【转】placement new

    原文:http://www.cnblogs.com/wanghetao/archive/2011/11/21/2257403.html 1. placement new的含义placement new ...

  9. 从零开始学android开发-项目debug

    在红框处能看到变量值

  10. poj 1147 Binary codes

    Binary codes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5647   Accepted: 2201 Desc ...