Skip to content

Commit 358bd6b

Browse files
committed
2009-07-02 Atsushi Enomoto <[email protected]>
* ContractDescriptionGenerator.cs : actually it had to fill all of the interface methods (and implementation methods). * ContractDescriptionTest.cs : make sure the contract actually contains operations from the base types. svn path=/trunk/mcs/; revision=137307
1 parent ec0d50c commit 358bd6b

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

mcs/class/System.ServiceModel/System.ServiceModel.Description/ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2009-07-02 Atsushi Enomoto <[email protected]>
2+
3+
* ContractDescriptionGenerator.cs : actually it had to fill all of
4+
the interface methods (and implementation methods).
5+
16
2009-07-02 Atsushi Enomoto <[email protected]>
27

38
* ContractDescriptionGenerator.cs : do not reject derived service

mcs/class/System.ServiceModel/System.ServiceModel.Description/ContractDescriptionGenerator.cs

+21-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ public static ContractDescription GetContract (
136136
cd.ProtectionLevel = sca.ProtectionLevel;
137137

138138
// FIXME: load Behaviors
139-
MethodInfo [] contractMethods = exactContractType.GetMethods ();
139+
MethodInfo [] contractMethods = exactContractType.IsInterface ? GetAllMethods (exactContractType) : exactContractType.GetMethods ();
140140
MethodInfo [] serviceMethods = contractMethods;
141141
if (givenServiceType != null && exactContractType.IsInterface) {
142-
serviceMethods = givenServiceType.GetInterfaceMap (exactContractType).TargetMethods;
142+
var l = new List<MethodInfo> ();
143+
foreach (Type t in GetAllInterfaceTypes (exactContractType))
144+
l.AddRange (givenServiceType.GetInterfaceMap (t).TargetMethods);
145+
serviceMethods = l.ToArray ();
143146
}
144147

145148
for (int i = 0; i < contractMethods.Length; ++i)
@@ -176,6 +179,22 @@ public static ContractDescription GetContract (
176179
return cd;
177180
}
178181

182+
static MethodInfo [] GetAllMethods (Type type)
183+
{
184+
var l = new List<MethodInfo> ();
185+
foreach (var t in GetAllInterfaceTypes (type))
186+
l.AddRange (t.GetMethods ());
187+
return l.ToArray ();
188+
}
189+
190+
static IEnumerable<Type> GetAllInterfaceTypes (Type type)
191+
{
192+
yield return type;
193+
foreach (var t in type.GetInterfaces ())
194+
foreach (var tt in GetAllInterfaceTypes (t))
195+
yield return tt;
196+
}
197+
179198
static OperationDescription GetOrCreateOperation (
180199
ContractDescription cd, MethodInfo mi, MethodInfo serviceMethod,
181200
OperationContractAttribute oca,

mcs/class/System.ServiceModel/Test/System.ServiceModel.Description/ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2009-07-02 Atsushi Enomoto <[email protected]>
2+
3+
* ContractDescriptionTest.cs : make sure the contract actually
4+
contains operations from the base types.
5+
16
2009-07-02 Atsushi Enomoto <[email protected]>
27

38
* ContractDescriptionTest.cs : added test for derived contract type.

mcs/class/System.ServiceModel/Test/System.ServiceModel.Description/ContractDescriptionTest.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,12 @@ public void TestContractFromObject () {
413413
[Test]
414414
public void GetDerivedContract ()
415415
{
416-
ContractDescription.GetContract (typeof (IFoo3));
417-
ContractDescription.GetContract (typeof (Foo3));
416+
var cd = ContractDescription.GetContract (typeof (IFoo3));
417+
Assert.AreEqual (typeof (IFoo3), cd.ContractType, "#1");
418+
Assert.AreEqual (3, cd.Operations.Count, "#2");
419+
cd = ContractDescription.GetContract (typeof (Foo3));
420+
Assert.AreEqual (typeof (IFoo3), cd.ContractType, "#3");
421+
Assert.AreEqual (3, cd.Operations.Count, "#4");
418422
}
419423

420424
// It is for testing attribute search in interfaces.

0 commit comments

Comments
 (0)