























前几天写的实体和实体集合的代码,最后发现只能xml序列化,不能做soap的序列化。就更改了一下
现在一个实体分为四个类,以OrderInfo为例,四个类分别是
其中1,3配合使用,用于web模式,支持soap序列化,webservice等,
2,4配合使用,用于winform模式,支持数据绑定等。基本和扩展之间可以互相进行类型转换。
下面是具体的代码,有点长,但是结构应该还是比较清楚的。
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
5
namespace 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
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。