summaryrefslogtreecommitdiffstats
path: root/mono/DBusType/String.cs
diff options
context:
space:
mode:
authorOwen Fraser-Green <owen@discobabe.net>2004-03-23 12:10:32 +0000
committerOwen Fraser-Green <owen@discobabe.net>2004-03-23 12:10:32 +0000
commitc916037773d7d3d8d37ca2c5a8899b7b728e377d (patch)
tree21c37372ab9795583e724e8459578b7fe0be330b /mono/DBusType/String.cs
parent2195cf0dbde2ae26b5a684c6d914c1711f44c28d (diff)
First checkin of the Mono bindings.
Diffstat (limited to 'mono/DBusType/String.cs')
-rw-r--r--mono/DBusType/String.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/mono/DBusType/String.cs b/mono/DBusType/String.cs
new file mode 100644
index 00000000..1eda1f25
--- /dev/null
+++ b/mono/DBusType/String.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Reflection.Emit;
+
+using DBus;
+
+namespace DBus.DBusType
+{
+ /// <summary>
+ /// A string.
+ /// </summary>
+ public class String : IDBusType
+ {
+ public const char Code = 's';
+ private string val;
+
+ private String()
+ {
+ }
+
+ public String(string val)
+ {
+ this.val = val;
+ }
+
+ public String(IntPtr iter)
+ {
+ this.val = Marshal.PtrToStringAnsi(dbus_message_iter_get_string(iter));
+ }
+
+ public void Append(IntPtr iter)
+ {
+ if (!dbus_message_iter_append_string(iter, Marshal.StringToHGlobalAnsi(val)))
+ throw new ApplicationException("Failed to append STRING argument:" + val);
+ }
+
+ public static bool Suits(System.Type type)
+ {
+ switch (type.ToString()) {
+ case "System.String":
+ case "System.String&":
+ return true;
+ }
+
+ return false;
+ }
+
+ public static void EmitMarshalIn(ILGenerator generator, Type type)
+ {
+ if (type.IsByRef) {
+ generator.Emit(OpCodes.Ldind_Ref);
+ }
+ }
+
+ public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn)
+ {
+ generator.Emit(OpCodes.Castclass, type);
+ if (!isReturn) {
+ generator.Emit(OpCodes.Stind_Ref);
+ }
+ }
+
+ public object Get()
+ {
+ return this.val;
+ }
+
+ public object Get(System.Type type)
+ {
+ switch (type.ToString())
+ {
+ case "System.String":
+ case "System.String&":
+ return this.val;
+ default:
+ throw new ArgumentException("Cannot cast DBus.Type.String to type '" + type.ToString() + "'");
+ }
+ }
+
+ [DllImport("dbus-1")]
+ private extern static IntPtr dbus_message_iter_get_string(IntPtr iter);
+
+ [DllImport("dbus-1")]
+ private extern static bool dbus_message_iter_append_string(IntPtr iter, IntPtr value);
+ }
+}