Exemplo n.º 1
0
        internal object InvokeMethod(PSMethod method, object[] arguments)
        {
            Type         type       = method.baseObject.GetType();
            BindingFlags invokeAttr = BindingFlags.InvokeMethod | BindingFlags.IgnoreCase;

            try
            {
                object[] objArray;
                ComMethodInformation[] informationArray  = ComUtil.GetMethodInformationArray(this.typeInfo, this.methods, false);
                ComMethodInformation   methodInformation = (ComMethodInformation)Adapter.GetBestMethodAndArguments(this.Name, (MethodInformation[])informationArray, arguments, out objArray);
                object obj2 = type.InvokeMember(this.Name, invokeAttr, null, method.baseObject, objArray, ComUtil.GetModifiers(methodInformation.parameters), CultureInfo.CurrentCulture, null);
                Adapter.SetReferences(objArray, methodInformation, arguments);
                if (methodInformation.ReturnType != typeof(void))
                {
                    return(obj2);
                }
                return(AutomationNull.Value);
            }
            catch (TargetInvocationException exception)
            {
                CommandProcessorBase.CheckForSevereException(exception.InnerException);
                COMException innerException = exception.InnerException as COMException;
                if ((innerException == null) || (innerException.ErrorCode != -2147352573))
                {
                    string str = (exception.InnerException == null) ? exception.Message : exception.InnerException.Message;
                    throw new MethodInvocationException("ComMethodTargetInvocation", exception, ExtendedTypeSystem.MethodInvocationException, new object[] { method.Name, arguments.Length, str });
                }
            }
            catch (COMException exception3)
            {
                if (exception3.ErrorCode != -2147352570)
                {
                    throw new MethodInvocationException("ComMethodCOMException", exception3, ExtendedTypeSystem.MethodInvocationException, new object[] { method.Name, arguments.Length, exception3.Message });
                }
            }
            return(null);
        }
Exemplo n.º 2
0
 internal void SetValue(object target, object setValue, object[] arguments)
 {
     using (ComProperty.tracer.TraceMethod())
     {
         object[]          newArguments;
         MethodInformation methodAndArguments = Adapter.GetBestMethodAndArguments(this.Name, (MethodInformation[])ComUtil.GetMethodInformationArray(this.typeInfo, new Collection <int>()
         {
             this.hasSetterByRef ? this.setterByRefIndex : this.setterIndex
         }, true), arguments, out newArguments);
         Type     type     = target.GetType();
         object[] objArray = new object[newArguments.Length + 1];
         for (int index = 0; index < newArguments.Length; ++index)
         {
             objArray[index] = newArguments[index];
         }
         objArray[newArguments.Length] = Adapter.PropertySetAndMethodArgumentConvertTo(setValue, this.Type, (IFormatProvider)CultureInfo.InvariantCulture);
         try
         {
             type.InvokeMember(this.name, BindingFlags.IgnoreCase | BindingFlags.SetProperty, (Binder)null, target, objArray, ComUtil.GetModifiers(methodAndArguments.parameters), CultureInfo.CurrentCulture, (string[])null);
             Adapter.SetReferences(objArray, methodAndArguments, arguments);
         }
         catch (TargetInvocationException ex)
         {
             CommandProcessorBase.CheckForSevereException(ex.InnerException);
             if (ex.InnerException is COMException innerException && innerException.ErrorCode == -2147352573)
             {
                 return;
             }
             throw;
         }
         catch (COMException ex)
         {
             if (ex.ErrorCode == -2147352570)
             {
                 return;
             }
             throw;
         }
     }
 }
Exemplo n.º 3
0
        internal object GetValue(object target, object[] arguments)
        {
            using (ComProperty.tracer.TraceMethod())
            {
                Type type = target.GetType();
                try
                {
                    object[]          newArguments;
                    MethodInformation methodAndArguments = Adapter.GetBestMethodAndArguments(this.Name, (MethodInformation[])ComUtil.GetMethodInformationArray(this.typeInfo, new Collection <int>()
                    {
                        this.getterIndex
                    }, false), arguments, out newArguments);
                    object obj = type.InvokeMember(this.name, BindingFlags.IgnoreCase | BindingFlags.GetProperty, (Binder)null, target, newArguments, ComUtil.GetModifiers(methodAndArguments.parameters), CultureInfo.CurrentCulture, (string[])null);
                    Adapter.SetReferences(newArguments, methodAndArguments, arguments);
                    return(obj);
                }
                catch (TargetInvocationException ex)
                {
                    CommandProcessorBase.CheckForSevereException(ex.InnerException);
                    if (ex.InnerException is COMException innerException)
                    {
                        if (innerException.ErrorCode == -2147352573)
                        {
                            goto label_8;
                        }
                    }
                    throw;
                }
                catch (COMException ex)
                {
                    if (ex.ErrorCode != -2147352570)
                    {
                        throw;
                    }
                }
label_8:
                return((object)null);
            }
        }
Exemplo n.º 4
0
        internal object InvokeMethod(PSMethod method, object[] arguments)
        {
            Type         type       = method.baseObject.GetType();
            BindingFlags invokeAttr = BindingFlags.IgnoreCase | BindingFlags.InvokeMethod;

            try
            {
                object[]             newArguments;
                ComMethodInformation methodAndArguments = (ComMethodInformation)Adapter.GetBestMethodAndArguments(this.Name, (MethodInformation[])ComUtil.GetMethodInformationArray(this.typeInfo, this.methods, false), arguments, out newArguments);
                object obj = type.InvokeMember(this.Name, invokeAttr, (Binder)null, method.baseObject, newArguments, ComUtil.GetModifiers(methodAndArguments.parameters), CultureInfo.CurrentCulture, (string[])null);
                Adapter.SetReferences(newArguments, (MethodInformation)methodAndArguments, arguments);
                return(methodAndArguments.ReturnType != typeof(void) ? obj : (object)AutomationNull.Value);
            }
            catch (TargetInvocationException ex)
            {
                CommandProcessorBase.CheckForSevereException(ex.InnerException);
                if (ex.InnerException is COMException innerException)
                {
                    if (innerException.ErrorCode == -2147352573)
                    {
                        goto label_9;
                    }
                }
                string str = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                throw new MethodInvocationException("ComMethodTargetInvocation", (Exception)ex, "ExtendedTypeSystem", "MethodInvocationException", new object[3]
                {
                    (object)method.Name,
                    (object)arguments.Length,
                    (object)str
                });
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode != -2147352570)
                {
                    throw new MethodInvocationException("ComMethodCOMException", (Exception)ex, "ExtendedTypeSystem", "MethodInvocationException", new object[3]
                    {
                        (object)method.Name,
                        (object)arguments.Length,
                        (object)ex.Message
                    });
                }
            }
label_9:
            return((object)null);
        }
Exemplo n.º 5
0
 internal object GetValue(object target, object[] arguments)
 {
     System.Type type = target.GetType();
     try
     {
         object[]         objArray;
         Collection <int> methods = new Collection <int> {
             this.getterIndex
         };
         MethodInformation[] informationArray  = ComUtil.GetMethodInformationArray(this.typeInfo, methods, false);
         MethodInformation   methodInformation = Adapter.GetBestMethodAndArguments(this.Name, informationArray, arguments, out objArray);
         object obj2 = type.InvokeMember(this.name, BindingFlags.GetProperty | BindingFlags.IgnoreCase, null, target, objArray, ComUtil.GetModifiers(methodInformation.parameters), CultureInfo.CurrentCulture, null);
         Adapter.SetReferences(objArray, methodInformation, arguments);
         return(obj2);
     }
     catch (TargetInvocationException exception)
     {
         CommandProcessorBase.CheckForSevereException(exception.InnerException);
         COMException innerException = exception.InnerException as COMException;
         if ((innerException == null) || (innerException.ErrorCode != -2147352573))
         {
             throw;
         }
     }
     catch (COMException exception3)
     {
         if (exception3.ErrorCode != -2147352570)
         {
             throw;
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        internal void SetValue(object target, object setValue, object[] arguments)
        {
            object[]         objArray;
            Collection <int> methods = new Collection <int> {
                (this.hasSetterByRef != null) ? this.setterByRefIndex : this.setterIndex
            };

            MethodInformation[] informationArray  = ComUtil.GetMethodInformationArray(this.typeInfo, methods, true);
            MethodInformation   methodInformation = Adapter.GetBestMethodAndArguments(this.Name, informationArray, arguments, out objArray);

            System.Type type = target.GetType();
            object[]    args = new object[objArray.Length + 1];
            for (int i = 0; i < objArray.Length; i++)
            {
                args[i] = objArray[i];
            }
            args[objArray.Length] = Adapter.PropertySetAndMethodArgumentConvertTo(setValue, this.Type, CultureInfo.InvariantCulture);
            try
            {
                type.InvokeMember(this.name, BindingFlags.SetProperty | BindingFlags.IgnoreCase, null, target, args, ComUtil.GetModifiers(methodInformation.parameters), CultureInfo.CurrentCulture, null);
                Adapter.SetReferences(args, methodInformation, arguments);
            }
            catch (TargetInvocationException exception)
            {
                CommandProcessorBase.CheckForSevereException(exception.InnerException);
                COMException innerException = exception.InnerException as COMException;
                if ((innerException == null) || (innerException.ErrorCode != -2147352573))
                {
                    throw;
                }
            }
            catch (COMException exception3)
            {
                if (exception3.ErrorCode != -2147352570)
                {
                    throw;
                }
            }
        }