2 using System.Runtime.InteropServices;
3 using System.Reflection.Emit;
7 namespace DBus.DBusType
12 public class UInt16 : IDBusType
14 public const char Code = 'q';
15 private System.UInt16 val;
21 public UInt16(System.UInt16 val, Service service)
26 public UInt16(IntPtr iter, Service service)
28 dbus_message_iter_get_basic (iter, out this.val);
31 public void Append(IntPtr iter)
33 if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
34 throw new ApplicationException("Failed to append INT16 argument:" + val);
37 public static bool Suits(System.Type type)
39 if (type.IsEnum && Enum.GetUnderlyingType (type) == typeof(System.UInt16)) {
43 switch (type.ToString()) {
45 case "System.UInt16&":
51 public static void EmitMarshalIn(ILGenerator generator, Type type)
54 generator.Emit(OpCodes.Ldind_U2);
58 public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
60 generator.Emit(OpCodes.Unbox, type);
61 generator.Emit(OpCodes.Ldind_U2);
63 generator.Emit(OpCodes.Stind_I2);
72 public object Get(System.Type type)
75 return Enum.ToObject(type, this.val);
78 switch (type.ToString()) {
80 case "System.UInt16&":
83 throw new ArgumentException("Cannot cast DBus.Type.UInt16 to type '" + type.ToString() + "'");
88 private extern static void dbus_message_iter_get_basic (IntPtr iter, out System.UInt16 value);
91 private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref System.UInt16 value);