Made all DBusTypes take Service in the constructor because Array also needed it in...
[platform/upstream/dbus.git] / mono / DBusType / Nil.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   /// Marks a "void"/"unset"/"nonexistent"/"null" argument.
11   /// </summary>
12   public class Nil : IDBusType
13   {
14     public const char Code = 'v';
15     
16     private Nil()
17     {
18     }
19     
20     public Nil(object nil, Service service) 
21     {
22     }
23
24     public Nil(IntPtr iter, Service service)
25     {
26     }
27     
28     public void Append(IntPtr iter)
29     {
30       if (!dbus_message_iter_append_nil(iter))
31         throw new ApplicationException("Failed to append NIL argument");
32     }
33
34     public static bool Suits(System.Type type) 
35     {
36       return false;
37     }
38
39     public static void EmitMarshalIn(ILGenerator generator, Type type)
40     {
41       if (type.IsByRef) {
42         generator.Emit(OpCodes.Ldind_I1);
43       }
44     }
45
46     public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) 
47     {
48       generator.Emit(OpCodes.Unbox, type);
49       generator.Emit(OpCodes.Ldind_I1);
50       if (!isReturn) {
51         generator.Emit(OpCodes.Stind_I1);
52       }
53     }
54     
55     public object Get() 
56     {
57       return null;
58     }
59
60     public object Get(System.Type type)
61     {
62       throw new ArgumentException("Cannot cast DBus.Type.Nil to type '" + type.ToString() + "'");
63     }
64
65     [DllImport("dbus-1")]
66     private extern static bool dbus_message_iter_append_nil(IntPtr iter);
67   }
68 }