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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
博客园 - 【当耐特】
WordPress大学
WordPress大学
爱范儿
爱范儿
美团技术团队
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
量子位
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
博客园 - 叶小钗
GbyAI
GbyAI
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Full Disclosure
G
Google Developers Blog
D
Docker
T
Tailwind CSS Blog
C
Check Point Blog
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
B
Blog
博客园 - 三生石上(FineUI控件)
博客园 - Franky
H
Help Net Security
MyScale Blog
MyScale Blog
U
Unit 42
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog

博客园 - 阿哲

SqlServer 2005 快速设置字段/表 的描述字段 将Visio文件装换成HTML文件(在服务器上转换,客户端无需安装visio即可查看) string:值类型?引用类型?[转] SqlServer2005常用sql语句 SQL中FOR XML子句的各种用法 获得Windows中文件类型名称 完成类似QQ邮箱中‘HTML方式查看’功能查看Office文件 vs2008生成自定义dll,VS2008发布、生成网站时设置固定的dll文件名 开源.Net CMS系统 [转] 测试使用Windows Live Writter写Blog 试用Windows Live Mail OutlookExpress使用技巧 剩余的GMail邀请 实体类+自定义控件=? 用反射+特性列出所有的枚举变量及其描述信息,绑定到DropDownList上。 有关.NET和RS232设备通讯 .NET资源(收藏) 转:使用P/Invoke来开发用于与串行设备通讯的.NET基类(翻译) 最近有空,研究了一下.NET的通讯方面
实体和实体的集合-续2
阿哲 · 2005-08-11 · via 博客园 - 阿哲

前几天写的实体和实体集合的代码,最后发现只能xml序列化,不能做soap的序列化。就更改了一下

现在一个实体分为四个类,以OrderInfo为例,四个类分别是

  1. OrderInfo : IEditableObject,IDataErrorInfo——实体类基本类,支持soap序列化
  2. OrderInfoEx : OrderInfo,IEditableObject——实体类扩展,不支持soap序列化,但是进一步支持数据绑定
  3. OrderInfoCollection : CollectionBase——实体集合类,支持soap序列化
  4. OrderInfoCollectionEx : OrderInfoCollection,IBindingList——实体集合扩展,支持数据绑定接口

其中1,3配合使用,用于web模式,支持soap序列化,webservice等,
2,4配合使用,用于winform模式,支持数据绑定等。基本和扩展之间可以互相进行类型转换。

下面是具体的代码,有点长,但是结构应该还是比较清楚的。




  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4
  5namespace Entity
  6{
  7    /// <summary>
  8    /// 类OrderInfo的集合
  9    /// </summary>

 10    [Serializable]
 11    public class OrderInfoCollectionEx : OrderInfoCollection,IBindingList
 12    {
 13        #region IBindingList 成员
 14
 15        private ListChangedEventArgs resetEvent = new ListChangedEventArgs(ListChangedType.Reset, -1);
 16        private ListChangedEventHandler onListChanged;
 17
 18        public bool AllowEdit 
 19        
 20            get {return true;}
 21        }

 22
 23        public bool AllowNew 
 24        
 25            get {return true;}
 26        }

 27
 28        public bool AllowRemove 
 29        
 30            get {return true;}
 31        }

 32
 33        public bool SupportsChangeNotification 
 34        
 35            get {return true;}
 36        }

 37
 38        public bool SupportsSearching 
 39        
 40            get {return false;}
 41        }

 42
 43        public bool SupportsSorting
 44        
 45            get {return false;}
 46        }

 47
 48        public void AddIndex(PropertyDescriptor property)
 49        {
 50            throw new NotSupportedException();
 51        }

 52        public void ApplySort(PropertyDescriptor property, System.ComponentModel.ListSortDirection direction)
 53        {
 54            throw new NotSupportedException();
 55        }

 56        public PropertyDescriptor SortProperty
 57        {
 58            get{throw new NotSupportedException();
 59                //return null;
 60            }

 61        }

 62        public int Find(PropertyDescriptor property, object key)
 63        {
 64            throw new NotSupportedException(); 
 65            //return 0;
 66        }

 67        public void RemoveSort()
 68        {
 69            throw new NotSupportedException(); 
 70        }

 71        public void RemoveIndex(PropertyDescriptor property)
 72        {
 73            throw new NotSupportedException(); 
 74        }

 75        public bool IsSorted
 76        {
 77            get throw new NotSupportedException();
 78            //return false;
 79            }

 80        }

 81        public System.ComponentModel.ListSortDirection SortDirection
 82        {
 83            get{throw new NotSupportedException();
 84                //return new System.ComponentModel.ListSortDirection ();
 85            }

 86        }

 87        public event ListChangedEventHandler ListChanged 
 88        {
 89            add{onListChanged += value;}
 90            remove{onListChanged -= value;}
 91        }

 92
 93        protected virtual void OnListChanged(ListChangedEventArgs ev) 
 94        {
 95            if (onListChanged != null
 96            {
 97                onListChanged(this, ev);
 98            }

 99        }

100        protected override void OnClearComplete() 
101        {
102            OnListChanged(resetEvent);
103        }

104
105        object IBindingList.AddNew()
106        {
107            OrderInfoEx c = new OrderInfoEx();
108            List.Add(c);
109            return c;
110        }

111        private void RemoveChild(Object source, OrderInfoEx.OrderInfoEventArgs e)
112        {
113            List.Remove(source);
114        }

115        protected override void OnInsertComplete(int index, object value) 
116        {
117            ((OrderInfoEx)(value)).RemoveMe += new OrderInfoEx.OrderInfoEventHandler(RemoveChild); 
118            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
119        }

120        protected override void OnRemoveComplete(int index, object value) 
121        {
122            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
123        }

124        protected override void OnSetComplete(int index, object oldValue, object newValue) 
125        {
126            if (oldValue != newValue) 
127            {
128                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
129            }

130        }

131
132
133        #endregion

134    }

135}