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/DBusType/String.cs | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 mono/DBusType/String.cs (limited to 'mono/DBusType/String.cs') diff --git a/mono/DBusType/String.cs b/mono/DBusType/String.cs new file mode 100644 index 00000000..1eda1f25 --- /dev/null +++ b/mono/DBusType/String.cs @@ -0,0 +1,86 @@ +using System; +using System.Runtime.InteropServices; +using System.Reflection.Emit; + +using DBus; + +namespace DBus.DBusType +{ + /// + /// A string. + /// + public class String : IDBusType + { + public const char Code = 's'; + private string val; + + private String() + { + } + + public String(string val) + { + this.val = val; + } + + public String(IntPtr iter) + { + this.val = Marshal.PtrToStringAnsi(dbus_message_iter_get_string(iter)); + } + + public void Append(IntPtr iter) + { + if (!dbus_message_iter_append_string(iter, Marshal.StringToHGlobalAnsi(val))) + throw new ApplicationException("Failed to append STRING argument:" + val); + } + + public static bool Suits(System.Type type) + { + switch (type.ToString()) { + case "System.String": + case "System.String&": + return true; + } + + return false; + } + + public static void EmitMarshalIn(ILGenerator generator, Type type) + { + if (type.IsByRef) { + generator.Emit(OpCodes.Ldind_Ref); + } + } + + public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) + { + generator.Emit(OpCodes.Castclass, type); + if (!isReturn) { + generator.Emit(OpCodes.Stind_Ref); + } + } + + public object Get() + { + return this.val; + } + + public object Get(System.Type type) + { + switch (type.ToString()) + { + case "System.String": + case "System.String&": + return this.val; + default: + throw new ArgumentException("Cannot cast DBus.Type.String to type '" + type.ToString() + "'"); + } + } + + [DllImport("dbus-1")] + private extern static IntPtr dbus_message_iter_get_string(IntPtr iter); + + [DllImport("dbus-1")] + private extern static bool dbus_message_iter_append_string(IntPtr iter, IntPtr value); + } +} -- cgit