Made all DBusTypes take Service in the constructor because Array also needed it in...
[platform/upstream/dbus.git] / mono / DBusType / UInt64.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Reflection.Emit;
4
5 using DBus;
6
7 namespace DBus.DBusType
8 {
9   /// <summary>
10   /// 64-bit unsigned integer.
11   /// </summary>
12   public class UInt64 : IDBusType
13   {
14     public const char Code = 't';
15     private System.UInt64 val;
16     
17     private UInt64()
18     {
19     }
20     
21     public UInt64(System.UInt64 val, Service service) 
22     {
23       this.val = val;
24     }
25
26     public UInt64(IntPtr iter, Service service)
27     {
28       this.val = dbus_message_iter_get_uint64(iter);
29     }
30     
31     public void Append(IntPtr iter)
32     {
33       if (!dbus_message_iter_append_uint64(iter, val))
34         throw new ApplicationException("Failed to append UINT64 argument:" + val);
35     }
36
37     public static bool Suits(System.Type type) 
38     {
39       switch (type.ToString()) {
40       case "System.UInt64":
41       case "System.UInt64&":
42         return true;
43       }
44       
45       return false;
46     }
47
48     public static void EmitMarshalIn(ILGenerator generator, Type type)
49     {
50       if (type.IsByRef) {
51         generator.Emit(OpCodes.Ldind_I8);
52       }
53     }
54
55     public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) 
56     {
57       generator.Emit(OpCodes.Unbox, type);
58       generator.Emit(OpCodes.Ldind_I8);
59       if (!isReturn) {
60         generator.Emit(OpCodes.Stind_I8);
61       }
62     }
63     
64     public object Get() 
65     {
66       return this.val;
67     }
68
69     public object Get(System.Type type)
70     {
71       switch (type.ToString()) 
72         {
73         case "System.UInt64":
74         case "System.UInt64&":
75           return this.val;
76         default:
77           throw new ArgumentException("Cannot cast DBus.Type.UInt64 to type '" + type.ToString() + "'");
78         }
79     }    
80
81     [DllImport("dbus-1")]
82     private extern static System.UInt64 dbus_message_iter_get_uint64(IntPtr iter);
83  
84     [DllImport("dbus-1")]
85     private extern static bool dbus_message_iter_append_uint64(IntPtr iter, System.UInt64 value);
86   }
87 }