dbus/mono/Introspector.cs

82 lines
1.8 KiB
C#
Raw Normal View History

2004-03-23 12:10:32 +00:00
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;
2004-03-23 12:10:32 +00:00
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);
2004-03-23 12:10:32 +00:00
this.type = type;
}
private void AddType(Type type)
2004-03-23 12:10:32 +00:00
{
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;
}
2004-03-23 12:10:32 +00:00
}
public Hashtable InterfaceProxies
2004-03-23 12:10:32 +00:00
{
get {
return this.interfaceProxies;
}
2004-03-23 12:10:32 +00:00
}
public ConstructorInfo Constructor
2004-03-23 12:10:32 +00:00
{
get {
ConstructorInfo ret = this.type.GetConstructor(new Type[0]);
if (ret != null) {
return ret;
} else {
return typeof(object).GetConstructor(new Type[0]);
2004-03-23 12:10:32 +00:00
}
}
2004-03-23 12:10:32 +00:00
}
public override string ToString()
2004-03-23 12:10:32 +00:00
{
return this.type.ToString();
2004-03-23 12:10:32 +00:00
}
}
}