forked from igorshmukler/XMLRPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XmlRpcProxyGen.cs
executable file
·619 lines (580 loc) · 22.5 KB
/
XmlRpcProxyGen.cs
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/*
XML-RPC.NET library
Copyright (c) 2001-2006, Charles Cook <[email protected]>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
namespace CookComputing.XmlRpc
{
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
public class XmlRpcProxyGen
{
static Hashtable _types = new Hashtable();
#if (!FX1_0)
public static T Create<T>()
{
return (T)Create(typeof(T));
}
#endif
public static object Create(Type itf)
{
// create transient assembly
Type proxyType;
lock (typeof(XmlRpcProxyGen))
{
proxyType = (Type)_types[itf];
if (proxyType == null)
{
Guid guid = Guid.NewGuid();
string assemblyName = "XmlRpcProxy" + guid.ToString();
string moduleName = "XmlRpcProxy" + guid.ToString() + ".dll";
string typeName = "XmlRpcProxy" + guid.ToString();
AssemblyBuilder assBldr = BuildAssembly(itf, assemblyName,
moduleName, typeName,
AssemblyBuilderAccess.Run
);
proxyType = assBldr.GetType(typeName);
_types.Add(itf, proxyType);
}
}
object ret = Activator.CreateInstance(proxyType);
return ret;
}
public static object CreateAssembly(
Type itf,
string typeName,
string assemblyName
)
{
// create persistable assembly
if (assemblyName.IndexOf(".dll") == (assemblyName.Length - 4))
assemblyName = assemblyName.Substring(0, assemblyName.Length - 4);
string moduleName = assemblyName + ".dll";
AssemblyBuilder assBldr = BuildAssembly(itf, assemblyName,
moduleName, typeName, AssemblyBuilderAccess.RunAndSave);
Type proxyType = assBldr.GetType(typeName);
object ret = Activator.CreateInstance(proxyType);
assBldr.Save(moduleName);
return ret;
}
static AssemblyBuilder BuildAssembly(
Type itf,
string assemblyName,
string moduleName,
string typeName,
AssemblyBuilderAccess access)
{
string urlString = GetXmlRpcUrl(itf);
ArrayList methods = GetXmlRpcMethods(itf);
ArrayList beginMethods = GetXmlRpcBeginMethods(itf);
ArrayList endMethods = GetXmlRpcEndMethods(itf);
AssemblyName assName = new AssemblyName();
assName.Name = assemblyName;
if (access == AssemblyBuilderAccess.RunAndSave)
assName.Version = itf.Assembly.GetName().Version;
AssemblyBuilder assBldr = AppDomain.CurrentDomain.DefineDynamicAssembly(
assName, access);
ModuleBuilder modBldr = (access == AssemblyBuilderAccess.Run
? assBldr.DefineDynamicModule(assName.Name)
: assBldr.DefineDynamicModule(assName.Name, moduleName));
TypeBuilder typeBldr = modBldr.DefineType(
typeName,
TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public,
typeof(XmlRpcClientProtocol),
new Type[] { itf });
BuildConstructor(typeBldr, typeof(XmlRpcClientProtocol), urlString);
BuildMethods(typeBldr, methods);
BuildBeginMethods(typeBldr, beginMethods);
BuildEndMethods(typeBldr, endMethods);
typeBldr.CreateType();
return assBldr;
}
static void BuildMethods(TypeBuilder tb, ArrayList methods)
{
foreach (MethodData mthdData in methods)
{
MethodInfo mi = mthdData.mi;
Type[] argTypes = new Type[mi.GetParameters().Length];
string[] paramNames = new string[mi.GetParameters().Length];
for (int i = 0; i < mi.GetParameters().Length; i++)
{
argTypes[i] = mi.GetParameters()[i].ParameterType;
paramNames[i] = mi.GetParameters()[i].Name;
}
XmlRpcMethodAttribute mattr = (XmlRpcMethodAttribute)
Attribute.GetCustomAttribute(mi, typeof(XmlRpcMethodAttribute));
BuildMethod(tb, mi.Name, mthdData.xmlRpcName, paramNames, argTypes,
mthdData.paramsMethod, mi.ReturnType, mattr.StructParams);
}
}
static void BuildMethod(
TypeBuilder tb,
string methodName,
string rpcMethodName,
string[] paramNames,
Type[] argTypes,
bool paramsMethod,
Type returnType,
bool structParams)
{
MethodBuilder mthdBldr = tb.DefineMethod(
methodName,
MethodAttributes.Public | MethodAttributes.Virtual,
returnType, argTypes);
// add attribute to method
Type[] oneString = new Type[1] { typeof(string) };
Type methodAttr = typeof(XmlRpcMethodAttribute);
ConstructorInfo ci = methodAttr.GetConstructor(oneString);
PropertyInfo[] pis
= new PropertyInfo[] { methodAttr.GetProperty("StructParams") };
object[] structParam = new object[] { structParams };
CustomAttributeBuilder cab =
new CustomAttributeBuilder(ci, new object[] { rpcMethodName },
pis, structParam);
mthdBldr.SetCustomAttribute(cab);
for (int i = 0; i < paramNames.Length; i++)
{
ParameterBuilder paramBldr = mthdBldr.DefineParameter(i + 1,
ParameterAttributes.In, paramNames[i]);
// possibly add ParamArrayAttribute to final parameter
if (i == paramNames.Length - 1 && paramsMethod)
{
ConstructorInfo ctorInfo = typeof(ParamArrayAttribute).GetConstructor(
new Type[0]);
CustomAttributeBuilder attrBldr =
new CustomAttributeBuilder(ctorInfo, new object[0]);
paramBldr.SetCustomAttribute(attrBldr);
}
}
// generate IL
ILGenerator ilgen = mthdBldr.GetILGenerator();
// if non-void return, declared locals for processing return value
LocalBuilder retVal = null;
LocalBuilder tempRetVal = null;
if (typeof(void) != returnType)
{
tempRetVal = ilgen.DeclareLocal(typeof(System.Object));
retVal = ilgen.DeclareLocal(returnType);
}
// declare variable to store method args and emit code to populate ut
LocalBuilder argValues = ilgen.DeclareLocal(typeof(System.Object[]));
ilgen.Emit(OpCodes.Ldc_I4, argTypes.Length);
ilgen.Emit(OpCodes.Newarr, typeof(System.Object));
ilgen.Emit(OpCodes.Stloc, argValues);
for (int argLoad = 0; argLoad < argTypes.Length; argLoad++)
{
ilgen.Emit(OpCodes.Ldloc, argValues);
ilgen.Emit(OpCodes.Ldc_I4, argLoad);
ilgen.Emit(OpCodes.Ldarg, argLoad + 1);
if (argTypes[argLoad].IsValueType)
{
ilgen.Emit(OpCodes.Box, argTypes[argLoad]);
}
ilgen.Emit(OpCodes.Stelem_Ref);
}
// call Invoke on base class
Type[] invokeTypes = new Type[] { typeof(MethodInfo), typeof(object[]) };
MethodInfo invokeMethod
= typeof(XmlRpcClientProtocol).GetMethod("Invoke", invokeTypes);
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Call, typeof(MethodBase).GetMethod("GetCurrentMethod"));
ilgen.Emit(OpCodes.Castclass, typeof(System.Reflection.MethodInfo));
ilgen.Emit(OpCodes.Ldloc, argValues);
ilgen.Emit(OpCodes.Call, invokeMethod);
// if non-void return prepare return value, otherwise pop to discard
if (typeof(void) != returnType)
{
// if return value is null, don't cast it to required type
Label retIsNull = ilgen.DefineLabel();
ilgen.Emit(OpCodes.Stloc, tempRetVal);
ilgen.Emit(OpCodes.Ldloc, tempRetVal);
ilgen.Emit(OpCodes.Brfalse, retIsNull);
ilgen.Emit(OpCodes.Ldloc, tempRetVal);
if (true == returnType.IsValueType)
{
ilgen.Emit(OpCodes.Unbox, returnType);
ilgen.Emit(OpCodes.Ldobj, returnType);
}
else
{
ilgen.Emit(OpCodes.Castclass, returnType);
}
ilgen.Emit(OpCodes.Stloc, retVal);
ilgen.MarkLabel(retIsNull);
ilgen.Emit(OpCodes.Ldloc, retVal);
}
else
{
ilgen.Emit(OpCodes.Pop);
}
ilgen.Emit(OpCodes.Ret);
}
static void BuildBeginMethods(TypeBuilder tb, ArrayList methods)
{
foreach (MethodData mthdData in methods)
{
MethodInfo mi = mthdData.mi;
// assume method has already been validated for required signature
int paramCount = mi.GetParameters().Length;
// argCount counts of params before optional AsyncCallback param
int argCount = paramCount;
Type[] argTypes = new Type[paramCount];
string[] paramNames = new string[mi.GetParameters().Length];
for (int i = 0; i < mi.GetParameters().Length; i++)
{
argTypes[i] = mi.GetParameters()[i].ParameterType;
paramNames[i] = mi.GetParameters()[i].Name;
if (argTypes[i] == typeof(System.AsyncCallback))
argCount = i;
}
XmlRpcBeginAttribute battr = (XmlRpcBeginAttribute)Attribute.GetCustomAttribute (mi, typeof(XmlRpcBeginAttribute));
bool structParams = battr.StructParams;
MethodBuilder mthdBldr = tb.DefineMethod(
mi.Name,
MethodAttributes.Public | MethodAttributes.Virtual,
mi.ReturnType,
argTypes);
// add attribute to method
Type[] oneString = new Type[1] { typeof(string) };
Type methodAttr = typeof(XmlRpcBeginAttribute);
ConstructorInfo ci = methodAttr.GetConstructor(oneString);
PropertyInfo[] pis = new PropertyInfo[] { methodAttr.GetProperty ("StructParams") };
object[] structParam = new object[] { structParams };
CustomAttributeBuilder cab = new CustomAttributeBuilder (ci, new object[] { mthdData.xmlRpcName },
pis, structParam);
mthdBldr.SetCustomAttribute(cab);
for (int i = 0; i < paramNames.Length; i++)
{
ParameterBuilder paramBldr = mthdBldr.DefineParameter(i + 1,
ParameterAttributes.In, paramNames[i]);
if (i == paramNames.Length - 1 && mthdData.paramsMethod)
{
ConstructorInfo ctorInfo = typeof(ParamArrayAttribute).GetConstructor(
new Type[0]);
CustomAttributeBuilder attrBldr =
new CustomAttributeBuilder(ctorInfo, new object[0]);
paramBldr.SetCustomAttribute(attrBldr);
}
}
// start generating IL
ILGenerator ilgen = mthdBldr.GetILGenerator();
// declare variable to store method args and emit code to populate it
LocalBuilder argValues = ilgen.DeclareLocal(typeof(System.Object[]));
ilgen.Emit(OpCodes.Ldc_I4, argCount);
ilgen.Emit(OpCodes.Newarr, typeof(System.Object));
ilgen.Emit(OpCodes.Stloc, argValues);
for (int argLoad = 0; argLoad < argCount; argLoad++)
{
ilgen.Emit(OpCodes.Ldloc, argValues);
ilgen.Emit(OpCodes.Ldc_I4, argLoad);
ilgen.Emit(OpCodes.Ldarg, argLoad + 1);
if (argTypes[argLoad].IsValueType)
{
ilgen.Emit(OpCodes.Box, argTypes[argLoad]);
}
ilgen.Emit(OpCodes.Stelem_Ref);
}
// emit code to store AsyncCallback parameter, defaulting to null
// if not in method signature
LocalBuilder acbValue = ilgen.DeclareLocal(typeof(System.AsyncCallback));
if (argCount < paramCount)
{
ilgen.Emit(OpCodes.Ldarg, argCount + 1);
ilgen.Emit(OpCodes.Stloc, acbValue);
}
// emit code to store async state parameter, defaulting to null
// if not in method signature
LocalBuilder objValue = ilgen.DeclareLocal(typeof(System.Object));
if (argCount < (paramCount - 1))
{
ilgen.Emit(OpCodes.Ldarg, argCount + 2);
ilgen.Emit(OpCodes.Stloc, objValue);
}
// emit code to call BeginInvoke on base class
Type[] invokeTypes = new Type[]
{
typeof(MethodInfo),
typeof(object[]),
typeof(System.Object),
typeof(System.AsyncCallback),
typeof(System.Object)
};
MethodInfo invokeMethod
= typeof(XmlRpcClientProtocol).GetMethod("BeginInvoke", invokeTypes);
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Call, typeof(MethodBase).GetMethod("GetCurrentMethod"));
ilgen.Emit(OpCodes.Castclass, typeof(System.Reflection.MethodInfo));
ilgen.Emit(OpCodes.Ldloc, argValues);
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldloc, acbValue);
ilgen.Emit(OpCodes.Ldloc, objValue);
ilgen.Emit(OpCodes.Call, invokeMethod);
// BeginInvoke will leave IAsyncResult on stack - leave it there
// for return value from method being built
ilgen.Emit(OpCodes.Ret);
}
}
static void BuildEndMethods(TypeBuilder tb, ArrayList methods)
{
LocalBuilder retVal = null;
LocalBuilder tempRetVal = null;
foreach (MethodData mthdData in methods)
{
MethodInfo mi = mthdData.mi;
Type[] argTypes = new Type[] { typeof(System.IAsyncResult) };
MethodBuilder mthdBldr = tb.DefineMethod(mi.Name,
MethodAttributes.Public | MethodAttributes.Virtual,
mi.ReturnType, argTypes);
// start generating IL
ILGenerator ilgen = mthdBldr.GetILGenerator();
// if non-void return, declared locals for processing return value
if (typeof(void) != mi.ReturnType)
{
tempRetVal = ilgen.DeclareLocal(typeof(System.Object));
retVal = ilgen.DeclareLocal(mi.ReturnType);
}
// call EndInvoke on base class
Type[] invokeTypes
= new Type[] { typeof(System.IAsyncResult), typeof(System.Type) };
MethodInfo invokeMethod
= typeof(XmlRpcClientProtocol).GetMethod("EndInvoke", invokeTypes);
Type[] GetTypeTypes
= new Type[] { typeof(System.String) };
MethodInfo GetTypeMethod
= typeof(System.Type).GetMethod("GetType", GetTypeTypes);
ilgen.Emit(OpCodes.Ldarg_0); // "this"
ilgen.Emit(OpCodes.Ldarg_1); // IAsyncResult parameter
ilgen.Emit(OpCodes.Ldstr, mi.ReturnType.AssemblyQualifiedName);
ilgen.Emit(OpCodes.Call, GetTypeMethod);
ilgen.Emit(OpCodes.Call, invokeMethod);
// if non-void return prepare return value otherwise pop to discard
if (typeof(void) != mi.ReturnType)
{
// if return value is null, don't cast it to required type
Label retIsNull = ilgen.DefineLabel();
ilgen.Emit(OpCodes.Stloc, tempRetVal);
ilgen.Emit(OpCodes.Ldloc, tempRetVal);
ilgen.Emit(OpCodes.Brfalse, retIsNull);
ilgen.Emit(OpCodes.Ldloc, tempRetVal);
if (true == mi.ReturnType.IsValueType)
{
ilgen.Emit(OpCodes.Unbox, mi.ReturnType);
ilgen.Emit(OpCodes.Ldobj, mi.ReturnType);
}
else
{
ilgen.Emit(OpCodes.Castclass, mi.ReturnType);
}
ilgen.Emit(OpCodes.Stloc, retVal);
ilgen.MarkLabel(retIsNull);
ilgen.Emit(OpCodes.Ldloc, retVal);
}
else
{
// void method so throw away result from EndInvoke
ilgen.Emit(OpCodes.Pop);
}
ilgen.Emit(OpCodes.Ret);
}
}
private static void BuildConstructor(
TypeBuilder typeBldr,
Type baseType,
string urlStr)
{
ConstructorBuilder ctorBldr = typeBldr.DefineConstructor(
MethodAttributes.Public | MethodAttributes.SpecialName |
MethodAttributes.RTSpecialName | MethodAttributes.HideBySig,
CallingConventions.Standard,
Type.EmptyTypes);
if (urlStr != null && urlStr.Length > 0)
{
Type urlAttr = typeof(XmlRpcUrlAttribute);
Type[] oneString = new Type[1] { typeof(string) };
ConstructorInfo ci = urlAttr.GetConstructor(oneString);
CustomAttributeBuilder cab =
new CustomAttributeBuilder(ci, new object[] { urlStr });
typeBldr.SetCustomAttribute(cab);
}
ILGenerator ilgen = ctorBldr.GetILGenerator();
// Call the base constructor.
ilgen.Emit(OpCodes.Ldarg_0);
ConstructorInfo ctorInfo = baseType.GetConstructor(System.Type.EmptyTypes);
ilgen.Emit(OpCodes.Call, ctorInfo);
ilgen.Emit(OpCodes.Ret);
}
private static string GetXmlRpcUrl(Type itf)
{
Attribute attr = Attribute.GetCustomAttribute(itf,
typeof(XmlRpcUrlAttribute));
if (attr == null)
return null;
XmlRpcUrlAttribute xruAttr = attr as XmlRpcUrlAttribute;
string url = xruAttr.Uri;
return url;
}
/// <summary>
/// Type.GetMethods() does not return methods that a derived interface
/// inherits from its base interfaces; this method does.
/// </summary>
private static MethodInfo[] GetMethods(Type type)
{
MethodInfo[] methods = type.GetMethods();
if (!type.IsInterface)
{
return methods;
}
Type[] interfaces = type.GetInterfaces();
if (interfaces.Length == 0)
{
return methods;
}
ArrayList result = new ArrayList(methods);
foreach (Type itf in type.GetInterfaces())
{
result.AddRange(itf.GetMethods());
}
return (MethodInfo[])result.ToArray(typeof(MethodInfo));
}
private static ArrayList GetXmlRpcMethods(Type itf)
{
ArrayList ret = new ArrayList();
if (!itf.IsInterface)
throw new Exception("type not interface");
foreach (MethodInfo mi in GetMethods(itf))
{
string xmlRpcName = GetXmlRpcMethodName(mi);
if (xmlRpcName == null)
continue;
ParameterInfo[] pis = mi.GetParameters();
bool paramsMethod = pis.Length > 0 && Attribute.IsDefined(
pis[pis.Length - 1], typeof(ParamArrayAttribute));
ret.Add(new MethodData(mi, xmlRpcName, paramsMethod));
}
return ret;
}
private static string GetXmlRpcMethodName(MethodInfo mi)
{
Attribute attr = Attribute.GetCustomAttribute(mi,
typeof(XmlRpcMethodAttribute));
if (attr == null)
return null;
XmlRpcMethodAttribute xrmAttr = attr as XmlRpcMethodAttribute;
string rpcMethod = xrmAttr.Method;
if (rpcMethod == "")
{
rpcMethod = mi.Name;
}
return rpcMethod;
}
class MethodData
{
public MethodData(MethodInfo Mi, string XmlRpcName, bool ParamsMethod)
{
mi = Mi;
xmlRpcName = XmlRpcName;
paramsMethod = ParamsMethod;
returnType = null;
}
public MethodData(MethodInfo Mi, string XmlRpcName, bool ParamsMethod,
Type ReturnType)
{
mi = Mi;
xmlRpcName = XmlRpcName;
paramsMethod = ParamsMethod;
returnType = ReturnType;
}
public MethodInfo mi;
public string xmlRpcName;
public Type returnType;
public bool paramsMethod;
}
private static ArrayList GetXmlRpcBeginMethods(Type itf)
{
ArrayList ret = new ArrayList();
if (!itf.IsInterface)
throw new Exception("type not interface");
foreach (MethodInfo mi in itf.GetMethods())
{
Attribute attr = Attribute.GetCustomAttribute(mi,
typeof(XmlRpcBeginAttribute));
if (attr == null)
continue;
string rpcMethod = ((XmlRpcBeginAttribute)attr).Method;
if (rpcMethod == "")
{
if (!mi.Name.StartsWith("Begin") || mi.Name.Length <= 5)
throw new Exception(String.Format(
"method {0} has invalid signature for begin method",
mi.Name));
rpcMethod = mi.Name.Substring(5);
}
int paramCount = mi.GetParameters().Length;
int i;
for (i = 0; i < paramCount; i++)
{
Type paramType = mi.GetParameters()[0].ParameterType;
if (paramType == typeof(System.AsyncCallback))
break;
}
if (paramCount > 1)
{
if (i < paramCount - 2)
throw new Exception(String.Format(
"method {0} has invalid signature for begin method", mi.Name));
if (i == (paramCount - 2))
{
Type paramType = mi.GetParameters()[i + 1].ParameterType;
if (paramType != typeof(System.Object))
throw new Exception(String.Format(
"method {0} has invalid signature for begin method",
mi.Name));
}
}
ret.Add(new MethodData(mi, rpcMethod, false, null));
}
return ret;
}
private static ArrayList GetXmlRpcEndMethods(Type itf)
{
ArrayList ret = new ArrayList();
if (!itf.IsInterface)
throw new Exception("type not interface");
foreach (MethodInfo mi in itf.GetMethods())
{
Attribute attr = Attribute.GetCustomAttribute(mi,
typeof(XmlRpcEndAttribute));
if (attr == null)
continue;
ParameterInfo[] pis = mi.GetParameters();
if (pis.Length != 1)
throw new Exception(String.Format(
"method {0} has invalid signature for end method", mi.Name));
Type paramType = pis[0].ParameterType;
if (paramType != typeof(System.IAsyncResult))
throw new Exception(String.Format(
"method {0} has invalid signature for end method", mi.Name));
ret.Add(new MethodData(mi, "", false));
}
return ret;
}
}
}