summaryrefslogtreecommitdiffstats
path: root/mono/Introspector.cs
diff options
context:
space:
mode:
authorOwen Fraser-Green <owen@discobabe.net>2004-03-23 12:10:32 +0000
committerOwen Fraser-Green <owen@discobabe.net>2004-03-23 12:10:32 +0000
commitc916037773d7d3d8d37ca2c5a8899b7b728e377d (patch)
tree21c37372ab9795583e724e8459578b7fe0be330b /mono/Introspector.cs
parent2195cf0dbde2ae26b5a684c6d914c1711f44c28d (diff)
First checkin of the Mono bindings.
Diffstat (limited to 'mono/Introspector.cs')
-rw-r--r--mono/Introspector.cs106
1 files changed, 106 insertions, 0 deletions
diff --git a/mono/Introspector.cs b/mono/Introspector.cs
new file mode 100644
index 00000000..c7b9d05b
--- /dev/null
+++ b/mono/Introspector.cs
@@ -0,0 +1,106 @@
+namespace DBus
+{
+
+ using System;
+ using System.Runtime.InteropServices;
+ using System.Diagnostics;
+ using System.Collections;
+ using System.Reflection;
+
+ internal class Introspector
+ {
+ private Type type;
+ private string interfaceName;
+
+ public Introspector(Type type) {
+ object[] attributes = type.GetCustomAttributes(typeof(InterfaceAttribute), true);
+ if (attributes.Length != 1)
+ throw new ApplicationException("Type '" + type + "' is not a D-BUS interface.");
+
+ InterfaceAttribute interfaceAttribute = (InterfaceAttribute) attributes[0];
+
+ this.interfaceName = interfaceAttribute.InterfaceName;
+ this.type = type;
+ }
+
+ public string InterfaceName
+ {
+ get
+ {
+ return this.interfaceName;
+ }
+ }
+
+ 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 IntrospectorMethods Methods
+ {
+ get
+ {
+ return new IntrospectorMethods(this.type);
+ }
+ }
+
+ public class IntrospectorMethods : IEnumerable
+ {
+ private Type type;
+
+ public IntrospectorMethods(Type type)
+ {
+ this.type = type;
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ return new MethodEnumerator(this.type.GetMethods(BindingFlags.Public|BindingFlags.Instance).GetEnumerator());
+ }
+
+ private class MethodEnumerator : IEnumerator
+ {
+ private IEnumerator enumerator;
+
+ public MethodEnumerator(IEnumerator enumerator)
+ {
+ this.enumerator = enumerator;
+ }
+
+ public bool MoveNext()
+ {
+ while (enumerator.MoveNext()) {
+ MethodInfo method = (MethodInfo) enumerator.Current;
+ object[] attributes = method.GetCustomAttributes(typeof(MethodAttribute), true);
+ if (attributes.GetLength(0) > 0) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public void Reset()
+ {
+ enumerator.Reset();
+ }
+
+ public object Current
+ {
+ get
+ {
+ return enumerator.Current;
+ }
+ }
+ }
+ }
+ }
+}