summaryrefslogtreecommitdiffstats
path: root/mono/Introspector.cs
blob: 8e97abc670e44ac70a50ba553b628bbc1714898d (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
namespace DBus 
{
  
  using System;
  using System.Runtime.InteropServices;
  using System.Diagnostics;
  using System.Collections;
  using System.Reflection;
  
  internal class Introspector
  {
    private Type type;
    private static Hashtable introspectors = new Hashtable();
    private Hashtable interfaceProxies = null;
    
    public static Introspector GetIntrospector(Type type) 
    {
      if (!introspectors.Contains(type)) {
	introspectors[type] = new Introspector(type);
      }

      return (Introspector) introspectors[type];
    }

    private Introspector(Type type) 
    {
      interfaceProxies = new Hashtable();
      AddType(type);
      this.type = type;
    }
    
    private void AddType(Type type) 
    {
      if (type == typeof(object)) {
	// Base case
	return;
      }

      object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), false);
      if (attributes.Length >= 1) {
	// This is a D-BUS interface so add it to the hashtable
	InterfaceProxy interfaceProxy = InterfaceProxy.GetInterface(type);
	interfaceProxies.Add(interfaceProxy.InterfaceName, interfaceProxy);
      }

      AddType(type.BaseType);
    }
    
    public InterfaceProxy GetInterface(string interfaceName) {
      if (interfaceProxies.Contains(interfaceName)) {
	return (InterfaceProxy) interfaceProxies[interfaceName];
      } else {
	return null;
      }
    }

    public Hashtable InterfaceProxies
    {
      get {
	return this.interfaceProxies;
      }
    }

    public ConstructorInfo Constructor
    {
      get {
	ConstructorInfo ret = this.type.GetConstructor(new Type[0]);
	if (ret != null) {
	  return ret;
	} else {
	  return typeof(object).GetConstructor(new Type[0]);
	}
      }
    }

    public override string ToString()
    {
      return this.type.ToString();
    }
  }
}