Пример #1
0
 private PSListModifier CreatePSListModifier()
 {
     PSListModifier modifier = new PSListModifier();
     if (this.Add != null)
     {
         foreach (object obj2 in this.Add)
         {
             modifier.Add.Add(obj2);
         }
     }
     if (this.Remove != null)
     {
         foreach (object obj3 in this.Remove)
         {
             modifier.Remove.Add(obj3);
         }
     }
     if (this.Replace != null)
     {
         foreach (object obj4 in this.Replace)
         {
             modifier.Replace.Add(obj4);
         }
     }
     return modifier;
 }
Пример #2
0
        /// <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));
                    }
                }
            }
        }
Пример #3
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;
 }
Пример #4
0
 protected override void ProcessRecord()
 {
     if (this.Property != null)
     {
         if (this.InputObject == null)
         {
             base.WriteError(this.NewError("MissingInputObjectParameter", "MissingInputObjectParameter", null, new object[0]));
         }
         else
         {
             if (this.listModifier == null)
             {
                 this.listModifier = this.CreatePSListModifier();
             }
             PSMemberInfo info = this.InputObject.Members[this.Property];
             if (info != null)
             {
                 try
                 {
                     this.listModifier.ApplyTo(info.Value);
                     base.WriteObject(this.InputObject);
                 }
                 catch (PSInvalidOperationException exception)
                 {
                     base.WriteError(new ErrorRecord(exception, "ApplyFailed", ErrorCategory.InvalidOperation, null));
                 }
             }
             else
             {
                 base.WriteError(this.NewError("MemberDoesntExist", "MemberDoesntExist", this.InputObject, new object[] { this.Property }));
             }
         }
     }
 }