惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
aimingoo的专栏
aimingoo的专栏
IT之家
IT之家
G
Google Developers Blog
爱范儿
爱范儿
博客园 - 司徒正美
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
J
Java Code Geeks
The Cloudflare Blog
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Security Blog
Microsoft Security Blog
博客园 - Franky
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
宝玉的分享
宝玉的分享
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Hacker News: Front Page
H
Help Net Security
S
Security @ Cisco Blogs
V
V2EX
Security Archives - TechRepublic
Security Archives - TechRepublic
Stack Overflow Blog
Stack Overflow Blog
O
OpenAI News
L
LINUX DO - 最新话题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Secure Thoughts
Help Net Security
Help Net Security
F
Full Disclosure
博客园 - 叶小钗
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
K
Kaspersky official blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Vulnerabilities – Threatpost
P
Privacy International News Feed
Scott Helme
Scott Helme

博客园 - 戴玮

关于状态模式的思考 实在是忍受不了MSN的巨慢速度,重新换个地方 如果在网页中实现查找功能 asp.net2.0 页面生命周期方法 C#加密与解决 如何自定义一个模板列,并在后台加载 ASP.NET常用的代码集合 - 戴玮 - 博客园 触发器示例代码 ADO.NET2.0分页 - 戴玮 - 博客园 如何将枚举定义翻译成DataTable 网页中调用MSN添加好友工具 如何在XP SP2下面使用DTC Javascript 复制与粘贴 - 戴玮 - 博客园 如何在Component中取得Page对象 使用TransactionScope进行COM+事务处理 - 戴玮 - 博客园 如何在C#中使用EVAL方法 - 戴玮 - 博客园 巨NB的JAVASCRIPT代码 - 戴玮 - 博客园 9月25日C#->WebService中如何传递文件 解决了一年多的问题,狂喜(一年之前)
如何查找 Office Web 组件 (OWC) 编程文档和示例
戴玮 · 2006-11-15 · via 博客园 - 戴玮

如何序列化DataRow或者其他对象

[Serializable]
    public class Field : ISerializable
    {
        private string name = "";
        private DataRow dr = null;
        private string title = "";
        private int index = -1;

        public int Index
        {
            get { return this.index; }
            set { this.index = value; }
        }

        public string Title
        {
            get { return this.title; }
            set { this.title = value; }
        }

        public string FieldName
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public DataRow FieldInfo
        {
            get { return this.dr; }
            set { this.dr = value; }
        }

        public Field()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            this.dr = dt.NewRow();
            dt.Rows.Add(dr);
          
        }

        protected Field(SerializationInfo info, StreamingContext context)//特殊的构造函数,反序列化时自动调用
        {
            this.name = info.GetString("fieldname");
            this.title = info.GetString("fieldtitle");
            this.index = info.GetInt32("fieldindex");
            DataTable dt = info.GetValue("fieldinfo", new DataTable().GetType()) as DataTable;
            this.dr = dt.Rows[0];
        }

        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)//序列化时自动调用
        {
            info.AddValue("fieldname", this.name);
            info.AddValue("fieldtitle", this.title);
            info.AddValue("fieldindex", this.index);
            DataTable dt = this.dr.Table.Clone(); //datarow不能同时加入到两个DataTable中,必须先克隆一个
            DataRow row = dt.NewRow();
            row.ItemArray = dr.ItemArray;

            dt.Rows.Add(row);
            info.AddValue("fieldinfo", dt, dt.GetType());
        }

        public override string ToString()
        {
            return this.name;
        }

    }