blob: 6ccc9636590767ff93f77880df3861d9aee7a05b (
plain)
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
|
namespace DBus
{
using System;
using System.Collections;
using System.Reflection;
internal class InterfaceProxy
{
private static Hashtable interfaceProxies = new Hashtable();
private Hashtable methods = null;
private string interfaceName;
private InterfaceProxy(Type type)
{
object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), true);
InterfaceAttribute interfaceAttribute = (InterfaceAttribute) attributes[0];
this.interfaceName = interfaceAttribute.InterfaceName;
AddMethods(type);
}
private void AddMethods(Type type)
{
this.methods = new Hashtable();
foreach (MethodInfo method in type.GetMethods(BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly)) {
object[] attributes = method.GetCustomAttributes(typeof(MethodAttribute), true);
if (attributes.GetLength(0) > 0) {
methods.Add(GetKey(method), method);
}
}
}
public static InterfaceProxy GetInterface(Type type)
{
if (!interfaceProxies.Contains(type)) {
interfaceProxies[type] = new InterfaceProxy(type);
}
return (InterfaceProxy) interfaceProxies[type];
}
public bool HasMethod(string key)
{
return this.Methods.Contains(key);
}
public MethodInfo GetMethod(string key)
{
return (MethodInfo) this.Methods[key];
}
private string GetKey(MethodInfo method)
{
ParameterInfo[] pars = method.GetParameters();
string key = method.Name + " ";
foreach (ParameterInfo par in pars) {
if (!par.IsOut) {
Type dbusType = Arguments.MatchType(par.ParameterType);
key += Arguments.GetCode(dbusType);
}
}
return key;
}
public Hashtable Methods
{
get {
return this.methods;
}
}
public string InterfaceName
{
get {
return this.interfaceName;
}
}
}
}
|