Esempio n. 1
0
        //dynamically defines a Type for the proxy object using D-Bus introspection
        public object GetObject(string bus_name, ObjectPath path)
        {
            org.freedesktop.DBus.Introspectable intros = GetObject <org.freedesktop.DBus.Introspectable> (bus_name, path);
            string data = intros.Introspect();

            StringReader  sr   = new StringReader(data);
            XmlSerializer sz   = new XmlSerializer(typeof(Node));
            Node          node = (Node)sz.Deserialize(sr);

            Type type = TypeDefiner.Define(node.Interfaces);

            return(GetObject(type, bus_name, path));
        }
Esempio n. 2
0
        public Type ToType(ref int pos)
        {
            // TODO: Find a way to avoid these null checks everywhere.
            if (data == null)
            {
                return(typeof(void));
            }

            DType dtype = (DType)data[pos++];

            switch (dtype)
            {
            case DType.Invalid:
                return(typeof(void));

            case DType.Byte:
                return(typeof(byte));

            case DType.Boolean:
                return(typeof(bool));

            case DType.Int16:
                return(typeof(short));

            case DType.UInt16:
                return(typeof(ushort));

            case DType.Int32:
                return(typeof(int));

            case DType.UInt32:
                return(typeof(uint));

            case DType.Int64:
                return(typeof(long));

            case DType.UInt64:
                return(typeof(ulong));

            case DType.Single:                     // not supported by libdbus at time of writing
                return(typeof(float));

            case DType.Double:
                return(typeof(double));

            case DType.String:
                return(typeof(string));

            case DType.ObjectPath:
                return(typeof(ObjectPath));

            case DType.Signature:
                return(typeof(Signature));

            case DType.Array:
                //peek to see if this is in fact a dictionary
                if ((DType)data[pos] == DType.DictEntryBegin)
                {
                    //skip over the {
                    pos++;
                    Type keyType   = ToType(ref pos);
                    Type valueType = ToType(ref pos);
                    //skip over the }
                    pos++;
                    //return typeof (IDictionary<,>).MakeGenericType (new Type[] {keyType, valueType});
                    //workaround for Mono bug #81035 (memory leak)
                    return(Mapper.GetGenericType(typeof(IDictionary <,>), new Type[] { keyType, valueType }));
                }
                return(GetNextSignature(ref pos).ToType().MakeArrayType());

            case DType.Struct:
                return(typeof(ValueType));

            case DType.StructBegin:
            {
                if (!IsStruct)
                {
                    throw new Exception("Struct '" + Value + "' is incomplete");
                }
                var type = TypeDefiner.CreateStructType(this);
                // skip over struct
                while ((DType)data[pos] != DType.StructEnd)
                {
                    Type unusedType = ToType(ref pos);
                }
                //skip over the )
                pos++;
                return(type);
            }

            case DType.DictEntry:
                return(typeof(KeyValuePair <,>));

            case DType.Variant:
                return(typeof(object));

            default:
                throw new NotSupportedException("Parsing or converting this signature is not yet supported (signature was '" + this + "'), at DType." + dtype);
            }
        }