4 using System.Collections;
5 using System.Reflection;
7 internal class InterfaceProxy
9 private static Hashtable interfaceProxies = new Hashtable();
10 private Hashtable methods = null;
11 private Hashtable signals = null;
13 private string interfaceName;
15 private InterfaceProxy(Type type)
17 object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), true);
18 InterfaceAttribute interfaceAttribute = (InterfaceAttribute) attributes[0];
19 this.interfaceName = interfaceAttribute.InterfaceName;
24 // Add all the events with Signal attributes
25 private void AddSignals(Type type)
27 this.signals = new Hashtable();
28 foreach (EventInfo signal in type.GetEvents(BindingFlags.Public |
29 BindingFlags.Instance |
30 BindingFlags.DeclaredOnly)) {
31 object[] attributes = signal.GetCustomAttributes(typeof(SignalAttribute), false);
32 if (attributes.GetLength(0) > 0) {
33 MethodInfo invoke = signal.EventHandlerType.GetMethod("Invoke");
34 signals.Add(signal.Name + " " + GetSignature(invoke), signal);
39 // Add all the methods with Method attributes
40 private void AddMethods(Type type)
42 this.methods = new Hashtable();
43 foreach (MethodInfo method in type.GetMethods(BindingFlags.Public |
44 BindingFlags.Instance |
45 BindingFlags.DeclaredOnly)) {
46 object[] attributes = method.GetCustomAttributes(typeof(MethodAttribute), false);
47 if (attributes.GetLength(0) > 0) {
48 methods.Add(method.Name + " " + GetSignature(method), method);
54 public static InterfaceProxy GetInterface(Type type)
56 if (!interfaceProxies.Contains(type)) {
57 interfaceProxies[type] = new InterfaceProxy(type);
60 return (InterfaceProxy) interfaceProxies[type];
63 public bool HasMethod(string key)
65 return this.Methods.Contains(key);
68 public bool HasSignal(string key)
70 return this.Signals.Contains(key);
73 public EventInfo GetSignal(string key)
75 return (EventInfo) this.Signals[key];
78 public MethodInfo GetMethod(string key)
80 return (MethodInfo) this.Methods[key];
83 public static string GetSignature(MethodInfo method)
85 ParameterInfo[] pars = method.GetParameters();
88 foreach (ParameterInfo par in pars) {
90 Type dbusType = Arguments.MatchType(par.ParameterType);
91 key += Arguments.GetCode(dbusType);
98 public Hashtable Methods
105 public Hashtable Signals
112 public string InterfaceName
115 return this.interfaceName;