internal static bool TryGetInstanceMethod(object value, string memberName, out PSMethodInfo methodInfo) { PSMemberInfoInternalCollection <PSMemberInfo> pSMemberInfos = null; PSMemberInfo item; if (PSObject.HasInstanceMembers(value, out pSMemberInfos)) { item = pSMemberInfos[memberName]; } else { item = null; } PSMemberInfo pSMemberInfo = item; methodInfo = pSMemberInfo as PSMethodInfo; if (pSMemberInfo != null) { if (methodInfo != null) { return(true); } else { object[] typeFullName = new object[2]; typeFullName[0] = ParserOps.GetTypeFullName(value); typeFullName[1] = memberName; throw InterpreterError.NewInterpreterException(memberName, typeof(RuntimeException), null, "MethodNotFound", ParserStrings.MethodNotFound, typeFullName); } } else { return(false); } }
internal static object InvokeAdaptedMember(object obj, string methodName, object[] args) { TypeTable typeTable; ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); object obj1 = obj; if (executionContextFromTLS != null) { typeTable = executionContextFromTLS.TypeTable; } else { typeTable = null; } PSObject.AdapterSet mappedAdapter = PSObject.GetMappedAdapter(obj1, typeTable); PSMethodInfo pSMethodInfo = mappedAdapter.OriginalAdapter.BaseGetMember <PSMemberInfo>(obj, methodName) as PSMethodInfo; if (pSMethodInfo == null && mappedAdapter.DotNetAdapter != null) { pSMethodInfo = mappedAdapter.DotNetAdapter.BaseGetMember <PSMemberInfo>(obj, methodName) as PSMethodInfo; } if (pSMethodInfo == null) { object[] typeFullName = new object[2]; typeFullName[0] = ParserOps.GetTypeFullName(obj); typeFullName[1] = methodName; throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), null, "MethodNotFound", ParserStrings.MethodNotFound, typeFullName); } else { return(pSMethodInfo.Invoke(args)); } }
public void TooManyArgumentsForPSMethodInvoke() { var obj = new Object(); var psObject = new PSObject(obj); PSMethodInfo method = psObject.Methods.First(m => m.Name == "ToString"); MethodException ex = Assert.Throws <MethodException>(() => method.Invoke(1, 2, 3, 4, 5)); Assert.AreEqual("Cannot find an overload for \"ToString\" and the argument count: \"5\".", ex.Message); }
private void MethodCallWithArguments() { ReadOnlyPSMemberInfoCollection <PSMemberInfo> infos = this._inputObject.Members.Match(this._propertyOrMethodName, PSMemberTypes.ParameterizedProperty | PSMemberTypes.Methods); if (infos.Count > 1) { StringBuilder builder = new StringBuilder(); foreach (PSMemberInfo info in infos) { builder.AppendFormat(CultureInfo.InvariantCulture, " {0}", new object[] { info.Name }); } base.WriteError(GenerateNameParameterError("Name", InternalCommandStrings.AmbiguousMethodName, "AmbiguousMethodName", this._inputObject, new object[] { this._propertyOrMethodName, builder })); } else if ((infos.Count == 0) || !(infos[0] is PSMethodInfo)) { base.WriteError(GenerateNameParameterError("Name", InternalCommandStrings.MethodNotFound, "MethodNotFound", this._inputObject, new object[] { this._propertyOrMethodName })); } else { PSMethodInfo info2 = infos[0] as PSMethodInfo; StringBuilder builder2 = new StringBuilder(GetStringRepresentation(this._arguments[0])); for (int i = 1; i < this._arguments.Length; i++) { builder2.AppendFormat(CultureInfo.InvariantCulture, ", {0}", new object[] { GetStringRepresentation(this._arguments[i]) }); } string action = string.Format(CultureInfo.InvariantCulture, InternalCommandStrings.ForEachObjectMethodActionWithArguments, new object[] { info2.Name, builder2 }); try { if (base.ShouldProcess(this.targetString, action) && !this.BlockMethodInLanguageMode(this.InputObject)) { object obj2 = info2.Invoke(this._arguments); this.WriteToPipelineWithUnrolling(obj2); } } catch (PipelineStoppedException) { throw; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); base.WriteError(new ErrorRecord(exception, "MethodInvocationError", ErrorCategory.InvalidOperation, this._inputObject)); } } }
public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) { PSMemberInfo pSMemberInfo = null; BindingRestrictions bindingRestriction = null; bool flag = false; Type type = null; Expression expression; Type value; MethodInformation[] methodInformationArray; Type type1; if (target.HasValue) { DynamicMetaObject[] dynamicMetaObjectArray = args; if (!dynamicMetaObjectArray.Where <DynamicMetaObject>((DynamicMetaObject arg) => !arg.HasValue).Any <DynamicMetaObject>()) { object obj = PSObject.Base(target.Value); if (obj != null) { if (!this._getMemberBinder.HasInstanceMember || !PSGetMemberBinder.TryGetInstanceMember(target.Value, base.Name, out pSMemberInfo)) { PSMethodInfo pSMethodInfo = this._getMemberBinder.GetPSMemberInfo(target, out bindingRestriction, out flag, out type, null, null) as PSMethodInfo; DynamicMetaObject[] dynamicMetaObjectArray1 = args; BindingRestrictions bindingRestriction1 = bindingRestriction; bindingRestriction = dynamicMetaObjectArray1.Aggregate <DynamicMetaObject, BindingRestrictions>(bindingRestriction1, (BindingRestrictions current, DynamicMetaObject arg) => current.Merge(arg.PSGetMethodArgumentRestriction())); if (ExecutionContext.HasEverUsedConstrainedLanguage) { bindingRestriction = bindingRestriction.Merge(BinderUtils.GetLanguageModeCheckIfHasEverUsedConstrainedLanguage()); ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); DynamicMetaObject dynamicMetaObject = PSGetMemberBinder.EnsureAllowedInLanguageMode(executionContextFromTLS.LanguageMode, target, obj, base.Name, this._static, args, bindingRestriction, "MethodInvocationNotSupportedInConstrainedLanguage", ParserStrings.InvokeMethodConstrainedLanguage); if (dynamicMetaObject != null) { return(dynamicMetaObject.WriteToDebugLog(this)); } } if (flag) { PSObject pSObject = target.Value as PSObject; if (pSObject != null && (obj.GetType().Equals(typeof(Hashtable)) || obj.GetType().Equals(typeof(ArrayList)))) { if (!pSObject.isDeserialized) { bindingRestriction = bindingRestriction.Merge(BindingRestrictions.GetExpressionRestriction(Expression.Not(Expression.Field(target.Expression.Cast(typeof(PSObject)), CachedReflectionInfo.PSObject_isDeserialized)))); } else { pSMethodInfo = null; bindingRestriction = bindingRestriction.Merge(BindingRestrictions.GetExpressionRestriction(Expression.Field(target.Expression.Cast(typeof(PSObject)), CachedReflectionInfo.PSObject_isDeserialized))); } } PSMethod pSMethod = pSMethodInfo as PSMethod; if (pSMethod == null) { PSScriptMethod pSScriptMethod = pSMethodInfo as PSScriptMethod; if (pSScriptMethod == null) { PSCodeMethod pSCodeMethod = pSMethodInfo as PSCodeMethod; if (pSCodeMethod == null) { PSParameterizedProperty pSParameterizedProperty = pSMethodInfo as PSParameterizedProperty; if (pSParameterizedProperty == null) { if (errorSuggestion == null) { if (this._static) { value = (Type)target.Value; } else { value = PSObject.Base(target.Value).GetType(); } Type type2 = value; if (!this._static && !this._nonEnumerating && target.Value != AutomationNull.Value) { DynamicMetaObject dynamicMetaObject1 = PSEnumerableBinder.IsEnumerable(target); if (dynamicMetaObject1 != null) { return(this.InvokeMemberOnCollection(dynamicMetaObject1, args, type2, bindingRestriction)); } } Expression[] expressionArray = new Expression[2]; expressionArray[0] = Expression.Constant(type2.FullName); expressionArray[1] = Expression.Constant(base.Name); return(new DynamicMetaObject(Compiler.ThrowRuntimeError("MethodNotFound", ParserStrings.MethodNotFound, expressionArray), bindingRestriction).WriteToDebugLog(this)); } else { return(errorSuggestion.WriteToDebugLog(this)); } } else { DotNetAdapter.ParameterizedPropertyCacheEntry parameterizedPropertyCacheEntry = (DotNetAdapter.ParameterizedPropertyCacheEntry)pSParameterizedProperty.adapterData; PSInvokeMemberBinder pSInvokeMemberBinder = this; DynamicMetaObject dynamicMetaObject2 = target; DynamicMetaObject[] dynamicMetaObjectArray2 = args; BindingRestrictions bindingRestriction2 = bindingRestriction; if (this._propertySetter) { methodInformationArray = parameterizedPropertyCacheEntry.setterInformation; } else { methodInformationArray = parameterizedPropertyCacheEntry.getterInformation; } if (this._propertySetter) { type1 = typeof(SetValueInvocationException); } else { type1 = typeof(GetValueInvocationException); } return(pSInvokeMemberBinder.InvokeDotNetMethod(dynamicMetaObject2, dynamicMetaObjectArray2, bindingRestriction2, methodInformationArray, type1).WriteToDebugLog(this)); } } else { return(new DynamicMetaObject(PSInvokeMemberBinder.InvokeMethod(pSCodeMethod.CodeReference, null, args.Prepend <DynamicMetaObject>(target).ToArray <DynamicMetaObject>(), false).Cast(typeof(object)), bindingRestriction).WriteToDebugLog(this)); } } else { MethodInfo pSScriptMethodInvokeScript = CachedReflectionInfo.PSScriptMethod_InvokeScript; ConstantExpression constantExpression = Expression.Constant(base.Name); ConstantExpression constantExpression1 = Expression.Constant(pSScriptMethod.Script); Expression expression1 = target.Expression.Cast(typeof(object)); Type type3 = typeof(object); DynamicMetaObject[] dynamicMetaObjectArray3 = args; return(new DynamicMetaObject(Expression.Call(pSScriptMethodInvokeScript, constantExpression, constantExpression1, expression1, Expression.NewArrayInit(type3, dynamicMetaObjectArray3.Select <DynamicMetaObject, Expression>((DynamicMetaObject e) => e.Expression.Cast(typeof(object))))), bindingRestriction).WriteToDebugLog(this)); } } else { DotNetAdapter.MethodCacheEntry methodCacheEntry = (DotNetAdapter.MethodCacheEntry)pSMethod.adapterData; return(this.InvokeDotNetMethod(target, args, bindingRestriction, methodCacheEntry.methodInformationStructures, typeof(MethodException)).WriteToDebugLog(this)); } } else { if (!this._propertySetter) { MethodInfo pSInvokeMemberBinderInvokeAdaptedMember = CachedReflectionInfo.PSInvokeMemberBinder_InvokeAdaptedMember; Expression expression2 = PSGetMemberBinder.GetTargetExpr(target).Cast(typeof(object)); ConstantExpression constantExpression2 = Expression.Constant(base.Name); Type type4 = typeof(object); DynamicMetaObject[] dynamicMetaObjectArray4 = args; expression = Expression.Call(pSInvokeMemberBinderInvokeAdaptedMember, expression2, constantExpression2, Expression.NewArrayInit(type4, dynamicMetaObjectArray4.Select <DynamicMetaObject, Expression>((DynamicMetaObject arg) => arg.Expression.Cast(typeof(object))))); } else { MethodInfo pSInvokeMemberBinderInvokeAdaptedSetMember = CachedReflectionInfo.PSInvokeMemberBinder_InvokeAdaptedSetMember; Expression expression3 = PSGetMemberBinder.GetTargetExpr(target).Cast(typeof(object)); ConstantExpression constantExpression3 = Expression.Constant(base.Name); Type type5 = typeof(object); IEnumerable <DynamicMetaObject> dynamicMetaObjects = args.Take <DynamicMetaObject>((int)args.Length - 1); expression = Expression.Call(pSInvokeMemberBinderInvokeAdaptedSetMember, expression3, constantExpression3, Expression.NewArrayInit(type5, dynamicMetaObjects.Select <DynamicMetaObject, Expression>((DynamicMetaObject arg) => arg.Expression.Cast(typeof(object)))), args.Last <DynamicMetaObject>().Expression.Cast(typeof(object))); } return(new DynamicMetaObject(expression, bindingRestriction).WriteToDebugLog(this)); } } else { ParameterExpression parameterExpression = Expression.Variable(typeof(PSMethodInfo)); MethodCallExpression methodCallExpression = Expression.Call(CachedReflectionInfo.PSInvokeMemberBinder_TryGetInstanceMethod, target.Expression.Cast(typeof(object)), Expression.Constant(base.Name), parameterExpression); ParameterExpression parameterExpression1 = parameterExpression; MethodInfo pSMethodInfoInvoke = CachedReflectionInfo.PSMethodInfo_Invoke; Expression[] expressionArray1 = new Expression[1]; Expression[] expressionArray2 = expressionArray1; int num = 0; Type type6 = typeof(object); DynamicMetaObject[] dynamicMetaObjectArray5 = args; expressionArray2[num] = Expression.NewArrayInit(type6, dynamicMetaObjectArray5.Select <DynamicMetaObject, Expression>((DynamicMetaObject dmo) => dmo.Expression.Cast(typeof(object)))); ConditionalExpression conditionalExpression = Expression.Condition(methodCallExpression, Expression.Call(parameterExpression1, pSMethodInfoInvoke, expressionArray1), base.GetUpdateExpression(typeof(object))); ParameterExpression[] parameterExpressionArray = new ParameterExpression[1]; parameterExpressionArray[0] = parameterExpression; Expression[] expressionArray3 = new Expression[1]; expressionArray3[0] = conditionalExpression; return(new DynamicMetaObject(Expression.Block(parameterExpressionArray, expressionArray3), BinderUtils.GetVersionCheck(this._getMemberBinder, this._getMemberBinder._version)).WriteToDebugLog(this)); } } else { return(target.ThrowRuntimeError(args, BindingRestrictions.Empty, "InvokeMethodOnNull", ParserStrings.InvokeMethodOnNull, new Expression[0]).WriteToDebugLog(this)); } } } return(base.Defer(args.Prepend <DynamicMetaObject>(target).ToArray <DynamicMetaObject>())); }
protected override void ProcessRecord() { string sddlForm; ObjectSecurity objectSecurity = this.securityDescriptor as ObjectSecurity; if (this.inputObject == null) { if (this.Path != null) { if (objectSecurity != null) { if ((this.CentralAccessPolicy != null || this.ClearCentralAccessPolicy) && !DownLevelHelper.IsWin8AndAbove()) { Exception parameterBindingException = new ParameterBindingException(); base.WriteError(new ErrorRecord(parameterBindingException, "SetAcl_OperationNotSupported", ErrorCategory.InvalidArgument, null)); return; } else { if (this.CentralAccessPolicy == null || !this.ClearCentralAccessPolicy) { IntPtr zero = IntPtr.Zero; NativeMethods.TOKEN_PRIVILEGE tOKENPRIVILEGE = new NativeMethods.TOKEN_PRIVILEGE(); try { if (this.CentralAccessPolicy == null) { if (this.ClearCentralAccessPolicy) { zero = this.GetEmptySacl(); if (zero == IntPtr.Zero) { SystemException systemException = new SystemException(UtilsStrings.GetEmptySaclFail); base.WriteError(new ErrorRecord(systemException, "SetAcl_ClearCentralAccessPolicy", ErrorCategory.InvalidResult, null)); return; } } } else { zero = this.GetSaclWithCapId(this.CentralAccessPolicy); if (zero == IntPtr.Zero) { SystemException systemException1 = new SystemException(UtilsStrings.GetSaclWithCapIdFail); base.WriteError(new ErrorRecord(systemException1, "SetAcl_CentralAccessPolicy", ErrorCategory.InvalidResult, null)); return; } } string[] path = this.Path; for (int i = 0; i < (int)path.Length; i++) { string str = path[i]; Collection <PathInfo> pathInfos = new Collection <PathInfo>(); CmdletProviderContext cmdletProviderContext = base.CmdletProviderContext; cmdletProviderContext.PassThru = this.Passthru; if (!this.isLiteralPath) { pathInfos = base.SessionState.Path.GetResolvedPSPathFromPSPath(str, base.CmdletProviderContext); } else { ProviderInfo providerInfo = null; PSDriveInfo pSDriveInfo = null; string unresolvedProviderPathFromPSPath = base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(str, out providerInfo, out pSDriveInfo); pathInfos.Add(new PathInfo(pSDriveInfo, providerInfo, unresolvedProviderPathFromPSPath, base.SessionState)); cmdletProviderContext.SuppressWildcardExpansion = true; } foreach (PathInfo pathInfo in pathInfos) { if (!base.ShouldProcess(pathInfo.Path)) { continue; } try { base.InvokeProvider.SecurityDescriptor.Set(pathInfo.Path, objectSecurity, cmdletProviderContext); if (this.CentralAccessPolicy != null || this.ClearCentralAccessPolicy) { if (pathInfo.Provider.NameEquals(base.Context.ProviderNames.FileSystem)) { IntPtr tokenWithEnabledPrivilege = this.GetTokenWithEnabledPrivilege("SeSecurityPrivilege", tOKENPRIVILEGE); if (tokenWithEnabledPrivilege != IntPtr.Zero) { int num = NativeMethods.SetNamedSecurityInfo(pathInfo.ProviderPath, NativeMethods.SeObjectType.SE_FILE_OBJECT, NativeMethods.SecurityInformation.SCOPE_SECURITY_INFORMATION, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, zero); if (tokenWithEnabledPrivilege != IntPtr.Zero) { NativeMethods.TOKEN_PRIVILEGE tOKENPRIVILEGE1 = new NativeMethods.TOKEN_PRIVILEGE(); uint num1 = 0; NativeMethods.AdjustTokenPrivileges(tokenWithEnabledPrivilege, false, ref tOKENPRIVILEGE, Marshal.SizeOf(tOKENPRIVILEGE1), ref tOKENPRIVILEGE1, ref num1); NativeMethods.CloseHandle(tokenWithEnabledPrivilege); } if (num != 0) { SystemException win32Exception = new Win32Exception(num, UtilsStrings.SetCentralAccessPolicyFail); base.WriteError(new ErrorRecord(win32Exception, "SetAcl_SetNamedSecurityInfo", ErrorCategory.InvalidResult, null)); } } else { SystemException systemException2 = new SystemException(UtilsStrings.GetTokenWithEnabledPrivilegeFail); base.WriteError(new ErrorRecord(systemException2, "SetAcl_AdjustTokenPrivileges", ErrorCategory.InvalidResult, null)); return; } } else { Exception argumentException = new ArgumentException("Path"); base.WriteError(new ErrorRecord(argumentException, "SetAcl_Path", ErrorCategory.InvalidArgument, this.AclObject)); continue; } } } catch (NotSupportedException notSupportedException) { object[] objArray = new object[1]; objArray[0] = pathInfo.Path; ErrorRecord errorRecord = SecurityUtils.CreateNotSupportedErrorRecord(UtilsStrings.OperationNotSupportedOnPath, "SetAcl_OperationNotSupported", objArray); base.WriteError(errorRecord); } } } return; } finally { Marshal.FreeHGlobal(zero); } } else { Exception exception = new ArgumentException(UtilsStrings.InvalidCentralAccessPolicyParameters); ErrorRecord errorRecord1 = SecurityUtils.CreateInvalidArgumentErrorRecord(exception, "SetAcl_OperationNotSupported"); base.WriteError(errorRecord1); return; } } } else { Exception argumentException1 = new ArgumentException("AclObject"); base.WriteError(new ErrorRecord(argumentException1, "SetAcl_AclObject", ErrorCategory.InvalidArgument, this.AclObject)); return; } } else { Exception exception1 = new ArgumentException("Path"); base.WriteError(new ErrorRecord(exception1, "SetAcl_Path", ErrorCategory.InvalidArgument, this.AclObject)); } } else { PSMethodInfo item = this.inputObject.Methods["SetSecurityDescriptor"]; if (item == null) { ErrorRecord errorRecord2 = SecurityUtils.CreateNotSupportedErrorRecord(UtilsStrings.SetMethodNotFound, "SetAcl_OperationNotSupported", new object[0]); base.WriteError(errorRecord2); return; } else { CommonSecurityDescriptor commonSecurityDescriptor = this.securityDescriptor as CommonSecurityDescriptor; if (objectSecurity == null) { if (commonSecurityDescriptor == null) { Exception argumentException2 = new ArgumentException("AclObject"); base.WriteError(new ErrorRecord(argumentException2, "SetAcl_AclObject", ErrorCategory.InvalidArgument, this.AclObject)); return; } else { sddlForm = commonSecurityDescriptor.GetSddlForm(AccessControlSections.All); } } else { sddlForm = objectSecurity.GetSecurityDescriptorSddlForm(AccessControlSections.All); } try { object[] objArray1 = new object[1]; objArray1[0] = sddlForm; item.Invoke(objArray1); return; } catch (Exception exception3) { Exception exception2 = exception3; CommandProcessorBase.CheckForSevereException(exception2); ErrorRecord errorRecord3 = SecurityUtils.CreateNotSupportedErrorRecord(UtilsStrings.MethodInvokeFail, "SetAcl_OperationNotSupported", new object[0]); base.WriteError(errorRecord3); } } } }
protected override void ProcessRecord() { AccessControlSections accessControlSection = AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group; if (this.audit) { accessControlSection = accessControlSection | AccessControlSections.Audit; } if (this.inputObject == null) { string[] path = this.Path; for (int i = 0; i < (int)path.Length; i++) { string str = path[i]; List <string> strs = new List <string>(); string str1 = null; try { if (!this.isLiteralPath) { Collection <PathInfo> resolvedPSPathFromPSPath = base.SessionState.Path.GetResolvedPSPathFromPSPath(str, base.CmdletProviderContext); foreach (PathInfo pathInfo in resolvedPSPathFromPSPath) { strs.Add(pathInfo.Path); } } else { strs.Add(base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(str)); } foreach (string str2 in strs) { str1 = str2; CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(base.Context); cmdletProviderContext.SuppressWildcardExpansion = true; if (base.InvokeProvider.Item.Exists(str2, false, this.isLiteralPath)) { base.InvokeProvider.SecurityDescriptor.Get(str2, accessControlSection, cmdletProviderContext); Collection <PSObject> accumulatedObjects = cmdletProviderContext.GetAccumulatedObjects(); if (accumulatedObjects == null) { continue; } SecurityDescriptorCommandsBase.AddBrokeredProperties(accumulatedObjects, this.audit, this.allCentralAccessPolicies); base.WriteObject(accumulatedObjects, true); } else { ErrorRecord errorRecord = SecurityUtils.CreatePathNotFoundErrorRecord(str2, "GetAcl_PathNotFound"); base.WriteError(errorRecord); } } } catch (NotSupportedException notSupportedException) { object[] objArray = new object[1]; objArray[0] = str1; ErrorRecord errorRecord1 = SecurityUtils.CreateNotSupportedErrorRecord(UtilsStrings.OperationNotSupportedOnPath, "GetAcl_OperationNotSupported", objArray); base.WriteError(errorRecord1); } catch (ItemNotFoundException itemNotFoundException) { ErrorRecord errorRecord2 = SecurityUtils.CreatePathNotFoundErrorRecord(str, "GetAcl_PathNotFound_Exception"); base.WriteError(errorRecord2); } } } else { PSMethodInfo item = this.inputObject.Methods["GetSecurityDescriptor"]; if (item == null) { ErrorRecord errorRecord3 = SecurityUtils.CreateNotSupportedErrorRecord(UtilsStrings.GetMethodNotFound, "GetAcl_OperationNotSupported", new object[0]); base.WriteError(errorRecord3); return; } else { object commonSecurityDescriptor = null; try { commonSecurityDescriptor = PSObject.Base(item.Invoke(new object[0])); if (commonSecurityDescriptor as FileSystemSecurity == null) { commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, commonSecurityDescriptor.ToString()); } } catch (Exception exception1) { Exception exception = exception1; CommandProcessorBase.CheckForSevereException(exception); ErrorRecord errorRecord4 = SecurityUtils.CreateNotSupportedErrorRecord(UtilsStrings.MethodInvokeFail, "GetAcl_OperationNotSupported", new object[0]); base.WriteError(errorRecord4); return; } base.WriteObject(commonSecurityDescriptor, true); return; } } }
protected override void ProcessRecord() { string parameterSetName = base.ParameterSetName; if (parameterSetName == null) { return; } if (!(parameterSetName == "ScriptBlockSet")) { if (!(parameterSetName == "PropertyAndMethodSet")) { return; } } else { for (int i = this.start; i < this.end; i++) { if (this.scripts[i] != null) { this.scripts[i].InvokeUsingCmdlet(this, false, ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe, this.InputObject, new object[] { this.InputObject }, AutomationNull.Value, new object[0]); } } return; } this.targetString = string.Format(CultureInfo.InvariantCulture, InternalCommandStrings.ForEachObjectTarget, new object[] { GetStringRepresentation(this.InputObject) }); if (LanguagePrimitives.IsNull(this.InputObject)) { if ((this._arguments != null) && (this._arguments.Length > 0)) { base.WriteError(GenerateNameParameterError("InputObject", ParserStrings.InvokeMethodOnNull, "InvokeMethodOnNull", this._inputObject, new object[0])); return; } string action = string.Format(CultureInfo.InvariantCulture, InternalCommandStrings.ForEachObjectPropertyAction, new object[] { this._propertyOrMethodName }); if (base.ShouldProcess(this.targetString, action)) { if (base.Context.IsStrictVersion(2)) { base.WriteError(GenerateNameParameterError("InputObject", InternalCommandStrings.InputObjectIsNull, "InputObjectIsNull", this._inputObject, new object[0])); return; } base.WriteObject(null); } return; } ErrorRecord errorRecord = null; if ((this._arguments != null) && (this._arguments.Length > 0)) { this.MethodCallWithArguments(); } else { if (this.GetValueFromIDictionaryInput()) { return; } PSMemberInfo info = null; if (WildcardPattern.ContainsWildcardCharacters(this._propertyOrMethodName)) { ReadOnlyPSMemberInfoCollection <PSMemberInfo> infos = this._inputObject.Members.Match(this._propertyOrMethodName, PSMemberTypes.All); if (infos.Count > 1) { StringBuilder builder = new StringBuilder(); foreach (PSMemberInfo info2 in infos) { builder.AppendFormat(CultureInfo.InvariantCulture, " {0}", new object[] { info2.Name }); } base.WriteError(GenerateNameParameterError("Name", InternalCommandStrings.AmbiguousPropertyOrMethodName, "AmbiguousPropertyOrMethodName", this._inputObject, new object[] { this._propertyOrMethodName, builder })); return; } if (infos.Count == 1) { info = infos[0]; } } else { info = this._inputObject.Members[this._propertyOrMethodName]; } if (info == null) { errorRecord = GenerateNameParameterError("Name", InternalCommandStrings.PropertyOrMethodNotFound, "PropertyOrMethodNotFound", this._inputObject, new object[] { this._propertyOrMethodName }); } else { if (info is PSMethodInfo) { PSParameterizedProperty property = info as PSParameterizedProperty; if (property != null) { string str2 = string.Format(CultureInfo.InvariantCulture, InternalCommandStrings.ForEachObjectPropertyAction, new object[] { property.Name }); if (base.ShouldProcess(this.targetString, str2)) { base.WriteObject(info.Value); } return; } PSMethodInfo info3 = info as PSMethodInfo; try { string str3 = string.Format(CultureInfo.InvariantCulture, InternalCommandStrings.ForEachObjectMethodActionWithoutArguments, new object[] { info3.Name }); if (base.ShouldProcess(this.targetString, str3) && !this.BlockMethodInLanguageMode(this.InputObject)) { object obj2 = info3.Invoke(new object[0]); this.WriteToPipelineWithUnrolling(obj2); } goto Label_0451; } catch (PipelineStoppedException) { throw; } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); MethodException exception2 = exception as MethodException; if (((exception2 != null) && (exception2.ErrorRecord != null)) && (exception2.ErrorRecord.FullyQualifiedErrorId == "MethodCountCouldNotFindBest")) { base.WriteObject(info3.Value); } else { base.WriteError(new ErrorRecord(exception, "MethodInvocationError", ErrorCategory.InvalidOperation, this._inputObject)); } goto Label_0451; } } string str4 = string.Format(CultureInfo.InvariantCulture, InternalCommandStrings.ForEachObjectPropertyAction, new object[] { info.Name }); if (base.ShouldProcess(this.targetString, str4)) { try { this.WriteToPipelineWithUnrolling(info.Value); } catch (TerminateException) { throw; } catch (MethodException) { throw; } catch (PipelineStoppedException) { throw; } catch (Exception exception3) { CommandProcessorBase.CheckForSevereException(exception3); base.WriteObject(null); } } } } Label_0451: if (errorRecord != null) { string str5 = string.Format(CultureInfo.InvariantCulture, InternalCommandStrings.ForEachObjectPropertyAction, new object[] { this._propertyOrMethodName }); if (base.ShouldProcess(this.targetString, str5)) { if (base.Context.IsStrictVersion(2)) { base.WriteError(errorRecord); return; } base.WriteObject(null); } } }