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; } } }
/// <summary> /// Get value of this property /// </summary> /// <param name="target">instance of the object from which to get the property value</param> /// <param name="arguments">parameters to get the property value</param> /// <returns>value of the property</returns> internal object GetValue(Object target, Object[] arguments) { try { object[] newarguments; var getterCollection = new Collection <int> { _getterIndex }; var methods = ComUtil.GetMethodInformationArray(_typeInfo, getterCollection, false); var bestMethod = (ComMethodInformation)Adapter.GetBestMethodAndArguments(Name, methods, arguments, out newarguments); object returnValue = ComInvoker.Invoke(target as IDispatch, bestMethod.DispId, newarguments, ComInvoker.GetByRefArray(bestMethod.parameters, newarguments.Length, isPropertySet: false), bestMethod.InvokeKind); Adapter.SetReferences(newarguments, bestMethod, arguments); return(returnValue); } catch (TargetInvocationException te) { var innerCom = te.InnerException as COMException; if (innerCom == null || innerCom.HResult != ComUtil.DISP_E_MEMBERNOTFOUND) { throw; } } catch (COMException ce) { if (ce.HResult != ComUtil.DISP_E_UNKNOWNNAME) { throw; } } return(null); }
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); }