From c916037773d7d3d8d37ca2c5a8899b7b728e377d Mon Sep 17 00:00:00 2001 From: Owen Fraser-Green Date: Tue, 23 Mar 2004 12:10:32 +0000 Subject: First checkin of the Mono bindings. --- mono/Introspector.cs | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 mono/Introspector.cs (limited to 'mono/Introspector.cs') 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; + } + } + } + } + } +} -- cgit