/// <summary> /// Obtains the parameter information for a given FuncDesc. /// </summary> internal static ParameterInformation[] GetParameterInformation(COM.FUNCDESC funcdesc, bool skipLastParameter) { int cParams = funcdesc.cParams; if (skipLastParameter) { Diagnostics.Assert(cParams > 0, "skipLastParameter is only true for property setters where there is at least one parameter"); cParams--; } ParameterInformation[] parameters = new ParameterInformation[cParams]; IntPtr ElementDescriptionArrayPtr = funcdesc.lprgelemdescParam; int ElementDescriptionSize = Marshal.SizeOf <COM.ELEMDESC>(); for (int i = 0; i < cParams; i++) { COM.ELEMDESC ElementDescription; int ElementDescriptionArrayByteOffset; IntPtr ElementDescriptionPointer; bool fOptional = false; ElementDescription = new COM.ELEMDESC(); ElementDescriptionArrayByteOffset = i * ElementDescriptionSize; // Disable PRefast warning for converting to int32 and converting back into intptr. // Code below takes into account 32 bit vs 64 bit conversions #pragma warning disable 56515 if (IntPtr.Size == 4) { ElementDescriptionPointer = (IntPtr)(ElementDescriptionArrayPtr.ToInt32() + ElementDescriptionArrayByteOffset); } else { ElementDescriptionPointer = (IntPtr)(ElementDescriptionArrayPtr.ToInt64() + ElementDescriptionArrayByteOffset); } #pragma warning enable 56515 ElementDescription = Marshal.PtrToStructure <COM.ELEMDESC>(ElementDescriptionPointer); // get the type of parameter Type type = ComUtil.GetTypeFromTypeDesc(ElementDescription.tdesc); object defaultvalue = null; // check is this parameter is optional. if ((ElementDescription.desc.paramdesc.wParamFlags & COM.PARAMFLAG.PARAMFLAG_FOPT) != 0) { fOptional = true; defaultvalue = Type.Missing; } bool fByRef = (ElementDescription.desc.paramdesc.wParamFlags & COM.PARAMFLAG.PARAMFLAG_FOUT) != 0; parameters[i] = new ParameterInformation(type, fOptional, defaultvalue, fByRef); } return(parameters); }
internal Collection <string> MethodDefinitions() { Collection <string> collection = new Collection <string>(); foreach (int method in this.methods) { IntPtr ppFuncDesc; this.typeInfo.GetFuncDesc(method, out ppFuncDesc); string signatureFromFuncDesc = ComUtil.GetMethodSignatureFromFuncDesc(this.typeInfo, (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ppFuncDesc, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC)), false); collection.Add(signatureFromFuncDesc); this.typeInfo.ReleaseFuncDesc(ppFuncDesc); } return(collection); }
internal Collection <string> MethodDefinitions() { Collection <string> collection = new Collection <string>(); foreach (int num in this.methods) { IntPtr ptr; this.typeInfo.GetFuncDesc(num, out ptr); System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ptr, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC)); string item = ComUtil.GetMethodSignatureFromFuncDesc(this.typeInfo, funcdesc, false); collection.Add(item); this.typeInfo.ReleaseFuncDesc(ptr); } return(collection); }
/// <summary> /// Sets the value of the property. /// </summary> /// <param name="target">instance of the object to which to set the property value</param> /// <param name="setValue">value to set this property</param> /// <param name="arguments">parameters to set this property.</param> internal void SetValue(Object target, Object setValue, Object[] arguments) { object[] newarguments; var setterCollection = new Collection <int> { _hasSetterByRef?_setterByRefIndex : _setterIndex }; var methods = ComUtil.GetMethodInformationArray(_typeInfo, setterCollection, true); var bestMethod = (ComMethodInformation)Adapter.GetBestMethodAndArguments(Name, methods, arguments, out newarguments); var finalArguments = new object[newarguments.Length + 1]; for (int i = 0; i < newarguments.Length; i++) { finalArguments[i] = newarguments[i]; } finalArguments[newarguments.Length] = Adapter.PropertySetAndMethodArgumentConvertTo(setValue, Type, CultureInfo.InvariantCulture); try { ComInvoker.Invoke(target as IDispatch, bestMethod.DispId, finalArguments, ComInvoker.GetByRefArray(bestMethod.parameters, finalArguments.Length, isPropertySet: true), bestMethod.InvokeKind); Adapter.SetReferences(finalArguments, bestMethod, arguments); } catch (TargetInvocationException te) { //First check if this is a severe exception. CommandProcessorBase.CheckForSevereException(te.InnerException); 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; } } }
/// <summary> /// Converts a MethodBase[] into a MethodInformation[] /// </summary> /// <returns>the ComMethodInformation[] corresponding to methods</returns> internal static ComMethodInformation[] GetMethodInformationArray(COM.ITypeInfo typeInfo, Collection <int> methods, bool skipLastParameters) { int methodCount = methods.Count; int count = 0; ComMethodInformation[] returnValue = new ComMethodInformation[methodCount]; foreach (int index in methods) { IntPtr pFuncDesc; typeInfo.GetFuncDesc(index, out pFuncDesc); COM.FUNCDESC funcdesc = ClrFacade.PtrToStructure <COM.FUNCDESC>(pFuncDesc); returnValue[count++] = ComUtil.GetMethodInformation(funcdesc, skipLastParameters); typeInfo.ReleaseFuncDesc(pFuncDesc); } return(returnValue); }
internal string GetDefinition() { IntPtr ppFuncDesc = IntPtr.Zero; try { this.typeInfo.GetFuncDesc(this.GetFuncDescIndex(), out ppFuncDesc); return(ComUtil.GetMethodSignatureFromFuncDesc(this.typeInfo, (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ppFuncDesc, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC)), !this.hasGetter)); } finally { if (ppFuncDesc != IntPtr.Zero) { this.typeInfo.ReleaseFuncDesc(ppFuncDesc); } } }
/// <summary> /// Initializes the typeinfo object. /// </summary> private void Initialize() { if (_typeinfo != null) { COM.TYPEATTR typeattr = GetTypeAttr(_typeinfo); // Initialize the type information guid _guid = typeattr.guid; for (int i = 0; i < typeattr.cFuncs; i++) { COM.FUNCDESC funcdesc = GetFuncDesc(_typeinfo, i); if (funcdesc.memid == DISPID_NEWENUM) { NewEnumInvokeKind = funcdesc.invkind; } if ((funcdesc.wFuncFlags & 0x1) == 0x1) { // https://msdn.microsoft.com/library/ee488948.aspx // FUNCFLAGS -- FUNCFLAG_FRESTRICTED = 0x1: // Indicates that the function should not be accessible from macro languages. // This flag is intended for system-level functions or functions that type browsers should not display. // // For IUnknown methods (AddRef, QueryInterface and Release) and IDispatch methods (GetTypeInfoCount, GetTypeInfo, GetIDsOfNames and Invoke) // FUNCFLAG_FRESTRICTED (0x1) is set for the 'wFuncFlags' field continue; } string strName = ComUtil.GetNameFromFuncDesc(_typeinfo, funcdesc); switch (funcdesc.invkind) { case COM.INVOKEKIND.INVOKE_PROPERTYGET: case COM.INVOKEKIND.INVOKE_PROPERTYPUT: case COM.INVOKEKIND.INVOKE_PROPERTYPUTREF: AddProperty(strName, funcdesc, i); break; case COM.INVOKEKIND.INVOKE_FUNC: AddMethod(strName, i); break; } } } }
/// <summary> /// Invokes the method on object /// </summary> /// <param name="method">represents the instance of the method we want to invoke</param> /// <param name="arguments">parameters to be passed to the method</param> /// <returns>returns the value of method call</returns> internal object InvokeMethod(PSMethod method, object[] arguments) { try { object[] newarguments; var methods = ComUtil.GetMethodInformationArray(_typeInfo, _methods, false); var bestMethod = (ComMethodInformation)Adapter.GetBestMethodAndArguments(Name, methods, arguments, out newarguments); object returnValue = ComInvoker.Invoke(method.baseObject as IDispatch, bestMethod.DispId, newarguments, ComInvoker.GetByRefArray(bestMethod.parameters, newarguments.Length, isPropertySet: false), COM.INVOKEKIND.INVOKE_FUNC); Adapter.SetReferences(newarguments, bestMethod, arguments); return(bestMethod.ReturnType != typeof(void) ? returnValue : AutomationNull.Value); } catch (TargetInvocationException te) { //First check if this is a severe exception. CommandProcessorBase.CheckForSevereException(te.InnerException); var innerCom = te.InnerException as COMException; if (innerCom == null || innerCom.HResult != ComUtil.DISP_E_MEMBERNOTFOUND) { string message = te.InnerException == null ? te.Message : te.InnerException.Message; throw new MethodInvocationException( "ComMethodTargetInvocation", te, ExtendedTypeSystem.MethodInvocationException, method.Name, arguments.Length, message); } } catch (COMException ce) { if (ce.HResult != ComUtil.DISP_E_UNKNOWNNAME) { throw new MethodInvocationException( "ComMethodCOMException", ce, ExtendedTypeSystem.MethodInvocationException, method.Name, arguments.Length, ce.Message); } } return(null); }
internal static ComMethodInformation[] GetMethodInformationArray( ITypeInfo typeInfo, Collection <int> methods, bool skipLastParameters) { int count = methods.Count; int num = 0; ComMethodInformation[] methodInformationArray = new ComMethodInformation[count]; foreach (int method in methods) { IntPtr ppFuncDesc; typeInfo.GetFuncDesc(method, out ppFuncDesc); System.Runtime.InteropServices.ComTypes.FUNCDESC structure = (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(ppFuncDesc, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC)); methodInformationArray[num++] = ComUtil.GetMethodInformation(structure, skipLastParameters); typeInfo.ReleaseFuncDesc(ppFuncDesc); } return(methodInformationArray); }
internal string GetDefinition() { IntPtr pFuncDesc = IntPtr.Zero; try { _typeInfo.GetFuncDesc(GetFuncDescIndex(), out pFuncDesc); COM.FUNCDESC funcdesc = Marshal.PtrToStructure <COM.FUNCDESC>(pFuncDesc); return(ComUtil.GetMethodSignatureFromFuncDesc(_typeInfo, funcdesc, !IsGettable)); } finally { if (pFuncDesc != IntPtr.Zero) { _typeInfo.ReleaseFuncDesc(pFuncDesc); } } }
/// <summary> /// Returns the different method overloads signatures. /// </summary> /// <returns></returns> internal Collection <string> MethodDefinitions() { Collection <string> result = new Collection <string>(); foreach (int index in _methods) { IntPtr pFuncDesc; _typeInfo.GetFuncDesc(index, out pFuncDesc); COM.FUNCDESC funcdesc = Marshal.PtrToStructure <COM.FUNCDESC>(pFuncDesc); string signature = ComUtil.GetMethodSignatureFromFuncDesc(_typeInfo, funcdesc, false); result.Add(signature); _typeInfo.ReleaseFuncDesc(pFuncDesc); } return(result); }
private static ComMethodInformation GetMethodInformation( System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool skipLastParameter) { Type typeFromTypeDesc = ComUtil.GetTypeFromTypeDesc(funcdesc.elemdescFunc.tdesc); ParameterInformation[] parameterInformation1 = ComUtil.GetParameterInformation(funcdesc, skipLastParameter); bool hasoptional = false; foreach (ParameterInformation parameterInformation2 in parameterInformation1) { if (parameterInformation2.isOptional) { hasoptional = true; break; } } return(new ComMethodInformation(false, hasoptional, parameterInformation1, typeFromTypeDesc)); }
/// <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) { //First check if this is a severe exception. CommandProcessorBase.CheckForSevereException(te.InnerException); 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 string GetDefinition() { string str; IntPtr zero = IntPtr.Zero; try { this.typeInfo.GetFuncDesc(this.GetFuncDescIndex(), out zero); System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc = (System.Runtime.InteropServices.ComTypes.FUNCDESC)Marshal.PtrToStructure(zero, typeof(System.Runtime.InteropServices.ComTypes.FUNCDESC)); str = ComUtil.GetMethodSignatureFromFuncDesc(this.typeInfo, funcdesc, !this.hasGetter); } finally { if (zero != IntPtr.Zero) { this.typeInfo.ReleaseFuncDesc(zero); } } return(str); }
internal static string GetMethodSignatureFromFuncDesc( ITypeInfo typeinfo, System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool isPropertyPut) { StringBuilder stringBuilder = new StringBuilder(); string nameFromFuncDesc = ComUtil.GetNameFromFuncDesc(typeinfo, funcdesc); if (!isPropertyPut) { string stringFromTypeDesc = ComUtil.GetStringFromTypeDesc(typeinfo, funcdesc.elemdescFunc.tdesc); stringBuilder.Append(stringFromTypeDesc + " "); } stringBuilder.Append(nameFromFuncDesc); stringBuilder.Append(" ("); IntPtr lprgelemdescParam = funcdesc.lprgelemdescParam; int num1 = Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC)); for (int index = 0; index < (int)funcdesc.cParams; ++index) { System.Runtime.InteropServices.ComTypes.ELEMDESC elemdesc = new System.Runtime.InteropServices.ComTypes.ELEMDESC(); int num2 = index * num1; elemdesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(IntPtr.Size != 4 ? (IntPtr)(lprgelemdescParam.ToInt64() + (long)num2) : (IntPtr)(lprgelemdescParam.ToInt32() + num2), typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC)); string stringFromTypeDesc = ComUtil.GetStringFromTypeDesc(typeinfo, elemdesc.tdesc); if (index == 0 && isPropertyPut) { stringBuilder.Insert(0, stringFromTypeDesc + " "); } else { stringBuilder.Append(stringFromTypeDesc); if (index < (int)funcdesc.cParams - 1) { stringBuilder.Append(", "); } } } stringBuilder.Append(")"); return(stringBuilder.ToString()); }
internal static ParameterInformation[] GetParameterInformation( System.Runtime.InteropServices.ComTypes.FUNCDESC funcdesc, bool skipLastParameter) { int cParams = (int)funcdesc.cParams; if (skipLastParameter) { --cParams; } ParameterInformation[] parameterInformationArray = new ParameterInformation[cParams]; IntPtr lprgelemdescParam = funcdesc.lprgelemdescParam; int num1 = Marshal.SizeOf(typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC)); for (int index = 0; index < cParams; ++index) { System.Runtime.InteropServices.ComTypes.ELEMDESC elemdesc = new System.Runtime.InteropServices.ComTypes.ELEMDESC(); int num2 = index * num1; elemdesc = (System.Runtime.InteropServices.ComTypes.ELEMDESC)Marshal.PtrToStructure(IntPtr.Size != 4 ? (IntPtr)(lprgelemdescParam.ToInt64() + (long)num2) : (IntPtr)(lprgelemdescParam.ToInt32() + num2), typeof(System.Runtime.InteropServices.ComTypes.ELEMDESC)); Type typeFromTypeDesc = ComUtil.GetTypeFromTypeDesc(elemdesc.tdesc); object defaultValue = (object)null; bool isOptional; if ((elemdesc.desc.paramdesc.wParamFlags & System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOPT) != System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE) { isOptional = true; defaultValue = Type.Missing; } else { isOptional = false; } bool isByRef = false; if ((elemdesc.desc.paramdesc.wParamFlags & System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_FOUT) != System.Runtime.InteropServices.ComTypes.PARAMFLAG.PARAMFLAG_NONE) { isByRef = true; } parameterInformationArray[index] = new ParameterInformation(typeFromTypeDesc, isOptional, defaultValue, isByRef); } return(parameterInformationArray); }
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; } } }
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); }
private static string GetStringFromTypeDesc(ITypeInfo typeinfo, System.Runtime.InteropServices.ComTypes.TYPEDESC typedesc) { if (typedesc.vt == (short)26) { System.Runtime.InteropServices.ComTypes.TYPEDESC structure = (System.Runtime.InteropServices.ComTypes.TYPEDESC)Marshal.PtrToStructure(typedesc.lpValue, typeof(System.Runtime.InteropServices.ComTypes.TYPEDESC)); return(ComUtil.GetStringFromTypeDesc(typeinfo, structure)); } if (typedesc.vt == (short)27) { System.Runtime.InteropServices.ComTypes.TYPEDESC structure = (System.Runtime.InteropServices.ComTypes.TYPEDESC)Marshal.PtrToStructure(typedesc.lpValue, typeof(System.Runtime.InteropServices.ComTypes.TYPEDESC)); return("SAFEARRAY(" + ComUtil.GetStringFromTypeDesc(typeinfo, structure) + ")"); } if (typedesc.vt == (short)29) { return(ComUtil.GetStringFromCustomType(typeinfo, typedesc.lpValue)); } switch ((VarEnum)typedesc.vt) { case VarEnum.VT_EMPTY: return(""); case VarEnum.VT_I2: return("short"); case VarEnum.VT_I4: case VarEnum.VT_INT: case VarEnum.VT_HRESULT: return("int"); case VarEnum.VT_R4: return("float"); case VarEnum.VT_R8: return("double"); case VarEnum.VT_CY: return("currency"); case VarEnum.VT_DATE: return("Date"); case VarEnum.VT_BSTR: case VarEnum.VT_LPSTR: case VarEnum.VT_LPWSTR: return("string"); case VarEnum.VT_DISPATCH: return("IDispatch"); case VarEnum.VT_BOOL: return("bool"); case VarEnum.VT_VARIANT: return("Variant"); case VarEnum.VT_UNKNOWN: return("IUnknown"); case VarEnum.VT_DECIMAL: return("decimal"); case VarEnum.VT_I1: return("char"); case VarEnum.VT_UI1: return("byte"); case VarEnum.VT_UI2: return("ushort"); case VarEnum.VT_UI4: case VarEnum.VT_UINT: return("uint"); case VarEnum.VT_I8: return("int64"); case VarEnum.VT_UI8: return("uint64"); case VarEnum.VT_VOID: return("void"); case VarEnum.VT_CLSID: return("clsid"); case VarEnum.VT_ARRAY: return("object[]"); default: return("Unknown!"); } }
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; } } }
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); } }
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); }
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); }