1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
// **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
using System.Globalization;
namespace Ice
{
//
// These classes are custom hash code providers and comparers, so proxies can be
// inserted into hashed or ordered collections using just the identity, or
// the identity and the facet name as the hash key.
//
public class ProxyIdentityKey : System.Collections.IEqualityComparer, System.Collections.IComparer
{
public int GetHashCode(object obj)
{
return ((Ice.ObjectPrx)obj).ice_getIdentity().GetHashCode();
}
public new bool Equals(object obj1, object obj2)
{
try
{
return Compare(obj1, obj2) == 0;
}
catch(System.Exception)
{
return false;
}
}
public int Compare(object obj1, object obj2)
{
if(obj1 == null)
{
return obj2 == null ? 0 : -1;
}
else if(obj2 == null)
{
return 1;
}
else
{
if(!(obj1 is Ice.ObjectPrx))
{
throw new System.ArgumentException("Argument must be derived from Ice.ObjectPrx", "o1");
}
if(!(obj2 is Ice.ObjectPrx))
{
throw new System.ArgumentException("Argument must be derived from Ice.ObjectPrx", "o2");
}
Ice.Identity i1 = ((Ice.ObjectPrx)obj1).ice_getIdentity();
Ice.Identity i2 = ((Ice.ObjectPrx)obj2).ice_getIdentity();
int comp = string.Compare(i1.name, i2.name, false, CultureInfo.InvariantCulture);
if(comp != 0)
{
return comp;
}
return string.Compare(i1.category, i2.category, false, CultureInfo.InvariantCulture);
}
}
}
public class ProxyIdentityFacetKey : System.Collections.IEqualityComparer, System.Collections.IComparer
{
public int GetHashCode(object obj)
{
Ice.ObjectPrx o = (Ice.ObjectPrx)obj;
Ice.Identity identity = o.ice_getIdentity();
string facet = o.ice_getFacet();
return 5 * identity.GetHashCode() + facet.GetHashCode();
}
public new bool Equals(object obj1, object obj2)
{
try
{
return Compare(obj1, obj2) == 0;
}
catch(System.Exception)
{
return false;
}
}
public int Compare(object obj1, object obj2)
{
if(obj1 == null)
{
return obj2 == null ? 0 : -1;
}
else if(obj2 == null)
{
return 1;
}
else
{
if(!(obj1 is Ice.ObjectPrx))
{
throw new System.ArgumentException("Argument must be derived from Ice.ObjectPrx", "obj1");
}
if(!(obj2 is Ice.ObjectPrx))
{
throw new System.ArgumentException("Argument must be derived from Ice.ObjectPrx", "obj2");
}
Ice.ObjectPrx o1 = (Ice.ObjectPrx)obj1;
Ice.ObjectPrx o2 = (Ice.ObjectPrx)obj2;
Ice.Identity i1 = o1.ice_getIdentity();
Ice.Identity i2 = o2.ice_getIdentity();
int comp = string.Compare(i1.name, i2.name, false, CultureInfo.InvariantCulture);
if(comp != 0)
{
return comp;
}
comp = string.Compare(i1.category, i2.category, false, CultureInfo.InvariantCulture);
if(comp != 0)
{
return comp;
}
string facet1 = o1.ice_getFacet();
string facet2 = o2.ice_getFacet();
return string.Compare(facet1, facet2, false, CultureInfo.InvariantCulture);
}
}
}
}
|