private object AuxillaryInvokeMethod( ManagementObject obj, BaseWMIAdapter.WMIMethodCacheEntry mdata, object[] arguments) { MethodInformation[] methods = new MethodInformation[1] { mdata.MethodInfoStructure }; object[] newArguments; Adapter.GetBestMethodAndArguments(mdata.Name, methods, arguments, out newArguments); ParameterInformation[] parameters = mdata.MethodInfoStructure.parameters; Adapter.tracer.WriteLine("Parameters found {0}. Arguments supplied {0}", (object)parameters.Length, (object)newArguments.Length); ManagementBaseObject methodParameters = BaseWMIAdapter.CreateClassFrmObject((ManagementBaseObject)obj).GetMethodParameters(mdata.Name); for (int index = 0; index < parameters.Length; ++index) { BaseWMIAdapter.WMIParameterInformation parameterInformation = (BaseWMIAdapter.WMIParameterInformation)parameters[index]; if (index < arguments.Length && arguments[index] == null) { newArguments[index] = (object)null; } methodParameters[parameterInformation.Name] = newArguments[index]; } return(this.InvokeManagementMethod(obj, mdata.Name, methodParameters)); }
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); }
protected override object MethodInvoke(PSMethod method, object[] arguments) { ParameterInformation[] arguments1 = new ParameterInformation[arguments.Length]; for (int index = 0; index < arguments.Length; ++index) { arguments1[index] = new ParameterInformation(typeof(object), false, (object)null, false); } MethodInformation[] methods = new MethodInformation[1] { new MethodInformation(false, false, arguments1) }; object[] newArguments; Adapter.GetBestMethodAndArguments(method.Name, methods, arguments, out newArguments); DirectoryEntry baseObject = (DirectoryEntry)method.baseObject; Exception exception; try { return(baseObject.Invoke(method.Name, newArguments)); } catch (DirectoryServicesCOMException ex) { exception = (Exception)ex; } catch (TargetInvocationException ex) { exception = (Exception)ex; } catch (COMException ex) { exception = (Exception)ex; } return((DirectoryEntryAdapter.dotNetAdapter.GetDotNetMethod <PSMethod>(method.baseObject, method.name) ?? throw exception).Invoke(arguments)); }
public override object Invoke(params object[] arguments) { object[] objArray2; if (arguments == null) { throw PSTraceSource.NewArgumentNullException("arguments"); } object[] objArray = new object[arguments.Length + 1]; objArray[0] = base.instance; for (int i = 0; i < arguments.Length; i++) { objArray[i + 1] = arguments[i]; } Adapter.GetBestMethodAndArguments(this.codeReference[0].Name, this.codeReferenceMethodInformation, objArray, out objArray2); return(DotNetAdapter.AuxiliaryMethodInvoke(null, objArray2, this.codeReferenceMethodInformation[0], objArray)); }
/// <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; } } }
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); }
/// <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); }
/// <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); }
private object AuxillaryInvokeMethod(ManagementObject obj, WMIMethodCacheEntry mdata, object[] arguments) { object[] objArray; MethodInformation[] methods = new MethodInformation[] { mdata.MethodInfoStructure }; Adapter.GetBestMethodAndArguments(mdata.Name, methods, arguments, out objArray); ParameterInformation[] parameters = mdata.MethodInfoStructure.parameters; Adapter.tracer.WriteLine("Parameters found {0}. Arguments supplied {0}", new object[] { parameters.Length, objArray.Length }); ManagementBaseObject methodParameters = CreateClassFrmObject(obj).GetMethodParameters(mdata.Name); for (int i = 0; i < parameters.Length; i++) { WMIParameterInformation information = (WMIParameterInformation)parameters[i]; if ((i < arguments.Length) && (arguments[i] == null)) { objArray[i] = null; } methodParameters[information.Name] = objArray[i]; } return(this.InvokeManagementMethod(obj, mdata.Name, methodParameters)); }
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; } } }
protected override object MethodInvoke(PSMethod method, object[] arguments) { object[] objArray; Exception exception = null; ParameterInformation[] informationArray = new ParameterInformation[arguments.Length]; for (int i = 0; i < arguments.Length; i++) { informationArray[i] = new ParameterInformation(typeof(object), false, null, false); } MethodInformation[] methods = new MethodInformation[] { new MethodInformation(false, false, informationArray) }; Adapter.GetBestMethodAndArguments(method.Name, methods, arguments, out objArray); DirectoryEntry baseObject = (DirectoryEntry)method.baseObject; try { return(baseObject.Invoke(method.Name, objArray)); } #if !MONO catch (DirectoryServicesCOMException exception2) { exception = exception2; } #endif catch (TargetInvocationException exception3) { exception = exception3; } catch (COMException exception4) { exception = exception4; } PSMethod dotNetMethod = dotNetAdapter.GetDotNetMethod <PSMethod>(method.baseObject, method.name); if (dotNetMethod == null) { throw exception; } return(dotNetMethod.Invoke(arguments)); }
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 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); }
internal static object CallMethod(IScriptExtent errorPosition, object target, string methodName, PSMethodInvocationConstraints invocationConstraints, object[] paramArray, bool callStatic, object valueToSet) { PSMethodInfo staticCLRMember = null; MethodInformation methodInformation = null; object obj2 = null; PSObject obj3 = null; Type type; object obj4; if (LanguagePrimitives.IsNull(target)) { throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "InvokeMethodOnNull", ParserStrings.InvokeMethodOnNull, new object[0]); } obj2 = PSObject.Base(target); obj3 = PSObject.AsPSObject(target); CallsiteCacheEntryFlags none = CallsiteCacheEntryFlags.None; if (callStatic) { none |= CallsiteCacheEntryFlags.Static; type = (Type)obj2; } else { type = obj2.GetType(); } if (valueToSet != AutomationNull.Value) { none |= CallsiteCacheEntryFlags.ParameterizedSetter; } if (!obj3.isDeserialized) { methodInformation = Adapter.FindCachedMethod(type, methodName, invocationConstraints, paramArray, none); } if (methodInformation == null) { if (callStatic) { staticCLRMember = PSObject.GetStaticCLRMember(target, methodName) as PSMethod; } else { staticCLRMember = obj3.Members[methodName] as PSMethodInfo; } if (staticCLRMember == null) { string fullName = null; if (callStatic) { fullName = type.FullName; } else { fullName = GetTypeFullName(target); } if (valueToSet == AutomationNull.Value) { throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "MethodNotFound", ParserStrings.MethodNotFound, new object[] { fullName, methodName }); } throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "ParameterizedPropertyAssignmentFailed", ParserStrings.ParameterizedPropertyAssignmentFailed, new object[] { fullName, methodName }); } } try { if (methodInformation != null) { object[] objArray; PSObject.memberResolution.WriteLine("cache hit, Calling Method: {0}", new object[] { methodInformation.methodDefinition }); if (valueToSet != AutomationNull.Value) { DotNetAdapter.ParameterizedPropertyInvokeSet(methodName, obj2, valueToSet, new MethodInformation[] { methodInformation }, paramArray, false); return(valueToSet); } MethodInformation[] methods = new MethodInformation[] { methodInformation }; Adapter.GetBestMethodAndArguments(methodName, methods, paramArray, out objArray); return(DotNetAdapter.AuxiliaryMethodInvoke(obj2, objArray, methodInformation, paramArray)); } if (valueToSet != AutomationNull.Value) { PSParameterizedProperty property = staticCLRMember as PSParameterizedProperty; if (property == null) { throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "ParameterizedPropertyAssignmentFailed", ParserStrings.ParameterizedPropertyAssignmentFailed, new object[] { GetTypeFullName(target), methodName }); } property.InvokeSet(valueToSet, paramArray); return(valueToSet); } PSMethod method = staticCLRMember as PSMethod; if (method != null) { return(method.Invoke(invocationConstraints, paramArray)); } obj4 = staticCLRMember.Invoke(paramArray); } catch (MethodInvocationException exception) { if (exception.ErrorRecord.InvocationInfo == null) { exception.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition)); } throw; } catch (RuntimeException exception2) { if (exception2.ErrorRecord.InvocationInfo == null) { exception2.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition)); } throw; } catch (FlowControlException) { throw; } catch (ScriptCallDepthException) { throw; } catch (Exception exception3) { CommandProcessorBase.CheckForSevereException(exception3); throw InterpreterError.NewInterpreterExceptionByMessage(typeof(RuntimeException), errorPosition, exception3.Message, "MethodInvocationException", exception3); } return(obj4); }