/// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (Property != null)
            {
                if (InputObject == null)
                {
                    WriteError(NewError("MissingInputObjectParameter", "MissingInputObjectParameter", null));
                }
                else
                {
                    if (_listModifier == null)
                    {
                        _listModifier = CreatePSListModifier();
                    }

                    PSMemberInfo memberInfo = InputObject.Members[Property];
                    if (memberInfo != null)
                    {
                        try
                        {
                            _listModifier.ApplyTo(memberInfo.Value);
                            WriteObject(InputObject);
                        }
                        catch (PSInvalidOperationException e)
                        {
                            WriteError(new ErrorRecord(e, "ApplyFailed", ErrorCategory.InvalidOperation, null));
                        }
                    }
                    else
                    {
                        WriteError(NewError("MemberDoesntExist", "MemberDoesntExist", InputObject, Property));
                    }
                }
            }
        }
예제 #2
0
        private PSListModifier CreatePSListModifier()
        {
            PSListModifier listModifier = new PSListModifier();

            if (Add != null)
            {
                foreach (object obj in Add)
                {
                    listModifier.Add.Add(obj);
                }
            }
            if (Remove != null)
            {
                foreach (object obj in Remove)
                {
                    listModifier.Remove.Add(obj);
                }
            }
            if (Replace != null)
            {
                foreach (object obj in Replace)
                {
                    listModifier.Replace.Add(obj);
                }
            }
            return(listModifier);
        }