Main Page | Modules | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Namespace Members | Data Fields | Related Pages

Introspector.cs

00001 namespace DBus 
00002 {
00003   
00004   using System;
00005   using System.Runtime.InteropServices;
00006   using System.Diagnostics;
00007   using System.Collections;
00008   using System.Reflection;
00009   
00010   internal class Introspector
00011   {
00012     private Type type;
00013     private static Hashtable introspectors = new Hashtable();
00014     private Hashtable interfaceProxies = null;
00015     
00016     public static Introspector GetIntrospector(Type type) 
00017     {
00018       if (!introspectors.Contains(type)) {
00019         introspectors[type] = new Introspector(type);
00020       }
00021 
00022       return (Introspector) introspectors[type];
00023     }
00024 
00025     private Introspector(Type type) 
00026     {
00027       interfaceProxies = new Hashtable();
00028       AddType(type);
00029       this.type = type;
00030     }
00031     
00032     private void AddType(Type type) 
00033     {
00034       if (type == typeof(object)) {
00035         // Base case
00036         return;
00037       }
00038 
00039       object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), false);
00040       if (attributes.Length >= 1) {
00041         // This is a D-BUS interface so add it to the hashtable
00042         InterfaceProxy interfaceProxy = InterfaceProxy.GetInterface(type);
00043         interfaceProxies.Add(interfaceProxy.InterfaceName, interfaceProxy);
00044       }
00045 
00046       AddType(type.BaseType);
00047     }
00048     
00049     public InterfaceProxy GetInterface(string interfaceName) {
00050       if (interfaceProxies.Contains(interfaceName)) {
00051         return (InterfaceProxy) interfaceProxies[interfaceName];
00052       } else {
00053         return null;
00054       }
00055     }
00056 
00057     public Hashtable InterfaceProxies
00058     {
00059       get {
00060         return this.interfaceProxies;
00061       }
00062     }
00063 
00064     public ConstructorInfo Constructor
00065     {
00066       get {
00067         ConstructorInfo ret = this.type.GetConstructor(new Type[0]);
00068         if (ret != null) {
00069           return ret;
00070         } else {
00071           return typeof(object).GetConstructor(new Type[0]);
00072         }
00073       }
00074     }
00075 
00076     public override string ToString()
00077     {
00078       return this.type.ToString();
00079     }
00080   }
00081 }

Generated on Tue Sep 13 01:28:08 2005 for D-BUS by  doxygen 1.4.4