Beispiel #1
0
        public InspectableAdapter GetItem(uint index)
        {
            IntPtr pValue = IntPtr.Zero;

            PInvokeUtils.ThrowIfResult(NativeMethods.ObservableCollection_GetItem(this.Interface, index, ref pValue));
            return(ObjectStaticsUtil.CreateInspectable(pValue));
        }
        public InspectableAdapter GetProperty(uint propertyId)
        {
            IntPtr pValue = IntPtr.Zero;

            PInvokeUtils.ThrowIfResult(NativeMethods.ObjectDispatch_GetProperty(this.Interface, propertyId, ref pValue));
            return(ObjectStaticsUtil.CreateInspectable(pValue));
        }
        public InspectableAdapter Lookup(string key)
        {
            IntPtr pValue = IntPtr.Zero;

            PInvokeUtils.ThrowIfResult(NativeMethods.Dictionary_Lookup(this.Interface, key, ref pValue));
            return(ObjectStaticsUtil.CreateInspectable(pValue));
        }
Beispiel #4
0
        public InspectableAdapter GetResults()
        {
            IntPtr pValue = IntPtr.Zero;

            PInvokeUtils.ThrowIfResult(NativeMethods.AsyncOperation_GetResults(this.Interface, ref pValue));
            return(ObjectStaticsUtil.CreateInspectable(pValue));
        }
        public InspectableAdapter Execute(InspectableAdapter pParameter)
        {
            IntPtr result = IntPtr.Zero;

            PInvokeUtils.ThrowIfResult(NativeMethods.Command_Execute(
                                           this.Interface,
                                           pParameter != null ? pParameter.Interface:IntPtr.Zero,
                                           ref result));
            return(ObjectStaticsUtil.CreateInspectable(result));
        }
        public InspectableAdapter Invoke(uint methodId, InspectableAdapter[] parameters)
        {
            IntPtr[] pParameters = new IntPtr[parameters != null ? parameters.Length : 0];
            for (int index = 0; index < pParameters.Length; ++index)
            {
                var adapterParameter = parameters[index];
                pParameters[index] = adapterParameter != null ? adapterParameter.Interface : IntPtr.Zero;
            }
            IntPtr pResult = IntPtr.Zero;

            PInvokeUtils.ThrowIfResult(NativeMethods.ObjectDispatch_Invoke(this.Interface, methodId, (uint)pParameters.Length, pParameters, ref pResult));
            return(ObjectStaticsUtil.CreateInspectable(pResult));
        }
Beispiel #7
0
        static internal object ToFactoryObject(ClassFactory classFactory, InspectableAdapter adapter)
        {
            if (adapter == null)
            {
                return(null);
            }
            InspectableAdapter inspectableAdapter;
            EnumValueAdapter   enumValueAdapter = adapter as EnumValueAdapter;

            if (enumValueAdapter != null)
            {
                return(ToEnumValue(classFactory, enumValueAdapter));
            }
            PropertyValueAdapter pvAdapter = adapter as PropertyValueAdapter;

            if (pvAdapter != null)
            {
                if (pvAdapter.PropertyType == PropertyType.InspectableArray)
                {
                    IntPtr[] arrayObjects   = pvAdapter.GetInspectableArray();
                    object[] factoryObjects = new object[arrayObjects.Length];
                    for (int index = 0; index < arrayObjects.Length; ++index)
                    {
                        inspectableAdapter    = ObjectStaticsUtil.CreateInspectable(arrayObjects[index]);
                        factoryObjects[index] = ToFactoryObject(classFactory, inspectableAdapter);
                    }
                    return(factoryObjects);
                }
                return(pvAdapter.ToObject());
            }

            ObjectAdapter objectAdapter = adapter as ObjectAdapter;

            if (objectAdapter != null)
            {
                return(ToObject(classFactory, objectAdapter));
            }
            DictionaryAdapter dictionaryAdapter = adapter as DictionaryAdapter;

            if (dictionaryAdapter != null)
            {
                return(new Dictionary(dictionaryAdapter, classFactory));
            }
            inspectableAdapter = adapter as InspectableAdapter;
            if (inspectableAdapter != null)
            {
                return(new FactoryObject <InspectableAdapter>(inspectableAdapter, classFactory));
            }
            throw new NotImplementedException();
        }
        internal T ConvertTo <T>(object value)
        {
            if (value == null)
            {
                return(default(T));
            }
            Type     type     = typeof(T);
            TypeInfo typeInfo = type.GetTypeInfo();

            // if no conversion is needed
            if (typeInfo.IsSubclassOf(type) || value.GetType() == type)
            {
                return((T)value);
            }

            if (type == typeof(Dictionary))
            {
                ObservableObject observableObject = value as ObservableObject;
                if (observableObject != null)
                {
                    return(new Dictionary(
                               (DictionaryAdapter)ObjectStaticsUtil.CreateInspectable(
                                   observableObject.Adapter.Detach(),
                                   DictionaryAdapter.Type),
                               this.ClassFactory).AssertCast <T>());
                }
            }

            // support for arrays
            if (type.IsArray &&
                !(type.GetElementType().GetTypeInfo().IsPrimitive || type.GetElementType() == typeof(string)))
            {
                Array rawItems     = (Array)value;
                int   size         = rawItems.GetLength(0);
                Array adapterItems = Array.CreateInstance(type.GetElementType(), size);

                for (int index = 0; index < size; ++index)
                {
                    adapterItems.SetValue(ToFactoryObject(rawItems.GetValue(index).AssertCast <InspectableAdapter>()), index);
                }
                return(adapterItems.AssertCast <T>());
            }
            return(value.AssertCast <T>());
        }