Beispiel #1
0
        public int IndexOf(InspectableAdapter value)
        {
            Int32 index = 0;

            PInvokeUtils.ThrowIfResult(NativeMethods.ObservableCollection_IndexOf(this.Interface, value != null ? value.Interface:IntPtr.Zero, ref index));
            return(index);
        }
Beispiel #2
0
        private static IObject ActivateObjectInstance(ClassFactory classFactory, InspectableAdapter adapterInterface, Type type)
        {
            object o = Activator.CreateInstance(type, adapterInterface, classFactory);

            Debug.Assert(o is IObject);
            return((IObject)o);
        }
 public void SetProperty(uint propertyId, InspectableAdapter pValue)
 {
     PInvokeUtils.ThrowIfResult(NativeMethods.ObjectDispatch_SetProperty(
                                    this.Interface,
                                    propertyId,
                                    pValue != null ? pValue.Interface:IntPtr.Zero));
 }
Beispiel #4
0
        static internal InspectableAdapter ToAdapter(object o)
        {
            if (o == null)
            {
                return(null);
            }
            InspectableAdapter inspectableAdapter = o as InspectableAdapter;

            if (inspectableAdapter != null)
            {
                return(inspectableAdapter);
            }

            IFactoryObject factoryObject = o as IFactoryObject;

            // If we find an 'IFactoryObject' we will need to return the underlying Interface
            if (factoryObject != null)
            {
                return(factoryObject.Adapter);
            }
            if (o.GetType() == typeof(object[]))
            {
                object[] objs           = (object[])o;
                IntPtr[] objectAdapters = new IntPtr[objs.Length];
                for (int index = 0; index < objs.Length; ++index)
                {
                    inspectableAdapter    = ToAdapter(objs[index]);
                    objectAdapters[index] = inspectableAdapter != null ? inspectableAdapter.Interface : IntPtr.Zero;
                }
                return(new PropertyValueAdapter(objectAdapters));
            }
            // we assume can be constructed by a PropertyValue
            return(PropertyValueAdapter.CreateValue(o));
        }
        public bool CanExecute(InspectableAdapter pParameter)
        {
            bool canExecute = false;

            PInvokeUtils.ThrowIfResult(NativeMethods.Command_CanExecute(
                                           this.Interface,
                                           pParameter != null ? pParameter.Interface : IntPtr.Zero,
                                           ref canExecute));
            return(canExecute);
        }
        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));
        }
 internal static InspectableAdapter[] CreateInspectableArray(IntPtr[] pInterfaces)
 {
     System.Diagnostics.Debug.Assert(pInterfaces != null);
     InspectableAdapter[] result = new InspectableAdapter[pInterfaces.Length];
     for (int index = 0; index < pInterfaces.Length; ++index)
     {
         result[index] = CreateInspectable(pInterfaces[index]);
     }
     return(result);
 }
        public static ObjectAdapter ActivateObject(Guid iidType, InspectableAdapter pContext)
        {
            IntPtr pObject = IntPtr.Zero;

            PInvokeUtils.ThrowIfResult(NativeMethods.ObjectStaticsUtil_ActivateObject(
                                           ref iidType,
                                           pContext != null ? pContext.Interface : IntPtr.Zero,
                                           ref pObject));
            return(CreateObject(pObject, GetObjectType(pObject)));
        }
Beispiel #9
0
        public object Invoke(uint methodId, params object[] invokeParameters)
        {
            InspectableAdapter[] parameterAdapters = new InspectableAdapter[invokeParameters.Length];
            for (int index = 0; index < invokeParameters.Length; ++index)
            {
                parameterAdapters[index] = this.ToAdapter(invokeParameters[index]);
            }
            InspectableAdapter result = this.Adapter.Invoke(methodId, parameterAdapters);

            return(this.ToFactoryObject(result));
        }
        public bool Insert(string key, InspectableAdapter pValue)
        {
            bool replaced = false;

            PInvokeUtils.ThrowIfResult(NativeMethods.Dictionary_Insert(
                                           this.Interface,
                                           key,
                                           pValue != null ? pValue.Interface : IntPtr.Zero,
                                           ref replaced));

            return(replaced);
        }
Beispiel #11
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();
        }
Beispiel #12
0
        public TResult Execute(TParameter parameter)
        {
            InspectableAdapter result = this.Adapter.Execute(this.ToAdapter(parameter));

            if (typeof(TResult) != typeof(VoidModelType))
            {
                var factoryObject = ToFactoryObject(result);

                var typeInfo = typeof(TResult).GetTypeInfo();
                if (typeInfo.IsGenericType &&
                    typeInfo.GetGenericTypeDefinition() == typeof(Task <>))
                {
                    var asynOperation = factoryObject.AssertCast <IAsyncOperation>();
                    return(asynOperation.GetTask().AssertCast <TResult>());
                }
                return((TResult)factoryObject);
            }
            return(default(TResult));
        }
        internal static InspectableAdapter CreateInspectable(IntPtr pInterface, Guid iidType)
        {
            IntPtr pInterfaceCastTo = InspectableAdapter.CastToInternal(pInterface, iidType);

            NativeMethods.Inspectable_Release(pInterface);

            if (iidType == PropertyValueAdapter.Type)
            {
                return(new PropertyValueAdapter(pInterfaceCastTo));
            }
            else if (iidType == DictionaryAdapter.Type)
            {
                return(new DictionaryAdapter(pInterfaceCastTo));
            }
            else if (iidType == InspectableType)
            {
                return(new InspectableAdapter(pInterfaceCastTo));
            }
            return(CreateObject(pInterfaceCastTo, iidType));
        }
Beispiel #14
0
 public static void LogMessage(LoggerLevel level, uint messageId, string text, InspectableAdapter pParameter)
 {
     PInvokeUtils.ThrowIfResult(NativeMethods.Logger_LogMessage((uint)level, messageId, text, pParameter != null ? pParameter.Interface:IntPtr.Zero));
 }
Beispiel #15
0
 public object ToFactoryObject(InspectableAdapter adapter)
 {
     return(ClassFactory.ToFactoryObject(this.ClassFactory, adapter));
 }