2 using System.Runtime.InteropServices;
3 using System.Reflection.Emit;
7 namespace DBus.DBusType
12 public class String : IDBusType
14 public const char Code = 's';
21 public String(string val, Service service)
26 public String(IntPtr iter, Service service)
28 this.val = Marshal.PtrToStringAnsi(dbus_message_iter_get_string(iter));
31 public void Append(IntPtr iter)
33 if (!dbus_message_iter_append_string(iter, Marshal.StringToHGlobalAnsi(val)))
34 throw new ApplicationException("Failed to append STRING argument:" + val);
37 public static bool Suits(System.Type type)
39 switch (type.ToString()) {
41 case "System.String&":
48 public static void EmitMarshalIn(ILGenerator generator, Type type)
51 generator.Emit(OpCodes.Ldind_Ref);
55 public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
57 generator.Emit(OpCodes.Castclass, type);
59 generator.Emit(OpCodes.Stind_Ref);
68 public object Get(System.Type type)
70 switch (type.ToString())
73 case "System.String&":
76 throw new ArgumentException("Cannot cast DBus.Type.String to type '" + type.ToString() + "'");
81 private extern static IntPtr dbus_message_iter_get_string(IntPtr iter);
84 private extern static bool dbus_message_iter_append_string(IntPtr iter, IntPtr value);