Menu

[r513]: / phprpc_3.0 / dotNET / PHPRPC_InvocationHandler.cs  Maximize  Restore  History

Download this file

86 lines (84 with data), 3.8 kB

 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
/**********************************************************\
| |
| The implementation of PHPRPC Protocol 3.0 |
| |
| PHPRPC_InvocationHandler.cs |
| |
| Release 3.0.1 |
| Copyright (c) 2005-2008 by Team-PHPRPC |
| |
| WebSite: http://www.phprpc.org/ |
| http://www.phprpc.net/ |
| http://www.phprpc.com/ |
| http://sourceforge.net/projects/php-rpc/ |
| |
| Authors: Ma Bingyao <andot@ujn.edu.cn> |
| |
| This file may be distributed and/or modified under the |
| terms of the GNU Lesser General Public License (LGPL) |
| version 3.0 as published by the Free Software Foundation |
| and appearing in the included file LICENSE. |
| |
\**********************************************************/
/* PHPRPC Invocation Handler.
*
* Copyright (C) 2005-2008 Ma Bingyao <andot@ujn.edu.cn>
* Version: 3.0
* LastModified: Dec 19, 2008
* This library is free. You can redistribute it and/or modify it.
*/
#if !(PocketPC || Smartphone || WindowsCE)
namespace org.phprpc {
using System;
using System.Reflection;
using org.phprpc.util;
internal class PHPRPC_InvocationHandler : IInvocationHandler {
private PHPRPC_Client client;
public PHPRPC_InvocationHandler(PHPRPC_Client client) {
this.client = client;
}
private static Type[] ToTypes(ParameterInfo[] parameterInfos) {
Type[] types = new Type[parameterInfos.Length];
for (Int32 i = 0; i < parameterInfos.Length; i++) {
types[i] = parameterInfos[i].ParameterType;
}
return types;
}
public Object Invoke(Object proxy, MethodInfo method, Object[] args) {
Type[] paramTypes = ToTypes(method.GetParameters());
Int32 n = paramTypes.Length;
Boolean byRef = false;
for (Int32 i = 0; i < n; i++) {
if (paramTypes[i].IsByRef) {
byRef = true;
break;
}
}
#if !NET1
if ((n > 0) && ((paramTypes[n - 1] == typeof(PHPRPC_Callback)) || ((paramTypes[n - 1].IsGenericType) && (paramTypes[n - 1].GetGenericTypeDefinition() == typeof(PHPRPC_Callback<>))))) {
Object[] tmpargs = new Object[n - 1];
Array.Copy(args, tmpargs, n - 1);
client.Invoke(method.Name, tmpargs, (Delegate)args[n - 1], byRef);
return null;
}
#endif
#if SILVERLIGHT
throw new PHPRPC_Error(1, "SilverLight do not support synchronous invoke.");
#else
Object result = client.Invoke(method.Name, args, byRef);
if (result is PHPRPC_Error) {
throw (PHPRPC_Error)result;
}
if (byRef) {
for (Int32 i = 0; i < n; i++) {
if (paramTypes[i].IsByRef) {
args[i] = PHPConvert.ChangeType(args[i], paramTypes[i].GetElementType(), client.Charset);
}
}
}
return PHPConvert.ChangeType(result, method.ReturnType, client.Charset);
#endif
}
}
}
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.