2 using System.Runtime.InteropServices;
3 using System.Reflection.Emit;
7 namespace DBus.DBusType
12 public class Byte : IDBusType
14 public const char Code = 'y';
15 private System.Byte val;
21 public Byte(System.Byte val, Service service)
26 public Byte(System.Char val, Service service)
28 this.val = (byte) val;
31 public Byte(IntPtr iter, Service service)
33 dbus_message_iter_get_basic (iter, out this.val);
36 public void Append(IntPtr iter)
38 if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
39 throw new ApplicationException("Failed to append BYTE argument:" + val);
42 public static bool Suits(System.Type type)
44 if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.Byte)) {
48 switch (type.ToString()) {
59 public static void EmitMarshalIn(ILGenerator generator, Type type)
62 generator.Emit(OpCodes.Ldind_U1);
66 public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
68 generator.Emit(OpCodes.Unbox, type);
69 generator.Emit(OpCodes.Ldind_U1);
71 generator.Emit(OpCodes.Stind_I1);
80 public object Get(System.Type type)
83 return Enum.ToObject(type, this.val);
86 switch (type.ToString()) {
92 char charVal = (char) this.val;
95 throw new ArgumentException("Cannot cast DBus.Type.Byte to type '" + type.ToString() + "'");
100 private extern static void dbus_message_iter_get_basic (IntPtr iter, out byte value);
102 [DllImport("dbus-1")]
103 private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref byte value);