Esempio n. 1
0
 public static void SafeAdd(this PSMemberInfoCollection <PSPropertyInfo> t, PSPropertyInfo item)
 {
     if (null == t[item.Name])
     {
         t.Add(item);
     }
 }
Esempio n. 2
0
        protected void AddMemberToCollection <T>(PSMemberInfoCollection <T> collection, T member, bool force) where T : PSMemberInfo
        {
            var existingValue = collection[member.Name];

            if (existingValue != null)
            {
                if (force)
                {
                    collection.Remove(member.Name);
                }
                else
                {
                    var msg = String.Format("Member '{0}' already exists. Use force to overwrite.", member.Name);
                    ThrowTerminatingError(new ErrorRecord(new ArgumentException(msg), "MemberAlreadyExists",
                                                          ErrorCategory.InvalidArgument, member));
                }
            }
            collection.Add(member);
        }
        internal static void Add <T, TProp>(this PSMemberInfoCollection <PSPropertyInfo> props,
                                            T obj, Expression <Func <T, TProp> > memberExpression)
        {
            MemberInfo mi = null;

            if (memberExpression.Body is MemberExpression memEx)
            {
                mi = memEx.Member;
            }
            else if (memberExpression.Body is UnaryExpression unEx && unEx.Operand is MemberExpression unExMem)
            {
                mi = unExMem.Member;
            }

            if (mi != null)
            {
                Func <T, TProp> func = memberExpression.Compile();
                props.Add(new PSNoteProperty(mi.Name, func(obj)));
            }
        }
 private static void Add(this PSMemberInfoCollection <PSPropertyInfo> props, string name, object value)
 {
     props.Add(new PSNoteProperty(name, value));
 }
Esempio n. 5
0
 private void ReadMemberSet(PSMemberInfoCollection<PSMemberInfo> collection)
 {
     if (this.ReadStartElementAndHandleEmpty("MS"))
     {
         while (this._reader.NodeType == XmlNodeType.Element)
         {
             if (this.IsNextElement("MS"))
             {
                 string name = this.ReadNameAttribute();
                 PSMemberSet member = new PSMemberSet(name);
                 collection.Add(member);
                 this.ReadMemberSet(member.Members);
                 PSGetMemberBinder.SetHasInstanceMember(name);
             }
             else
             {
                 PSNoteProperty property = this.ReadNoteProperty();
                 collection.Add(property);
                 PSGetMemberBinder.SetHasInstanceMember(property.Name);
             }
         }
         this.ReadEndElement();
     }
 }