/// <summary>
        /// Append to a dictionary any properties that might have been added to an object (via PSObject) through the Add-Member cmdlet.
        /// If the passed in object is a custom object (not a simple object, not a dictionary, not a list, get processed in ProcessCustomObject method),
        /// we also take Adapted properties into account. Otherwise, we only consider the Extended properties.
        /// When the object is a pure PSObject, it also gets processed in "ProcessCustomObject" before reaching this method, so we will
        /// iterate both extended and adapted properties for it. Since it's a pure PSObject, there will be no adapted properties.
        /// </summary>
        /// <param name="psobj">The containing PSObject, or null if the base object was not contained in a PSObject.</param>
        /// <param name="receiver">The dictionary to which any additional properties will be appended.</param>
        /// <param name="depth">The current depth into the object graph.</param>
        /// <param name="isCustomObject">The processed object is a custom object.</param>
        private void AppendPsProperties(PSObject psobj, IDictionary receiver, int depth, bool isCustomObject)
        {
            // serialize only Extended and Adapted properties..
            PSMemberInfoCollection <PSPropertyInfo> srcPropertiesToSearch =
                new PSMemberInfoIntegratingCollection <PSPropertyInfo>(psobj,
                                                                       isCustomObject ? PSObject.GetPropertyCollection(PSMemberViewTypes.Extended | PSMemberViewTypes.Adapted) :
                                                                       PSObject.GetPropertyCollection(PSMemberViewTypes.Extended));

            foreach (PSPropertyInfo prop in srcPropertiesToSearch)
            {
                object value = null;
                try
                {
                    value = prop.Value;
                }
                catch (Exception)
                {
                }

                if (!receiver.Contains(prop.Name))
                {
                    receiver[prop.Name] = ProcessValue(value, depth + 1);
                }
            }
        }
Beispiel #2
0
 public PSMemberSet(string name, IEnumerable<PSMemberInfo> members)
 {
     this.inheritMembers = true;
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     base.name = name;
     if (members == null)
     {
         throw PSTraceSource.NewArgumentNullException("members");
     }
     this.internalMembers = new PSMemberInfoInternalCollection<PSMemberInfo>();
     foreach (PSMemberInfo info in members)
     {
         if (info == null)
         {
             throw PSTraceSource.NewArgumentNullException("members");
         }
         this.internalMembers.Add(info.Copy());
     }
     this.members = new PSMemberInfoIntegratingCollection<PSMemberInfo>(this, emptyMemberCollection);
     this.properties = new PSMemberInfoIntegratingCollection<PSPropertyInfo>(this, emptyPropertyCollection);
     this.methods = new PSMemberInfoIntegratingCollection<PSMethodInfo>(this, emptyMethodCollection);
 }
Beispiel #3
0
 internal IList<string> BuildPropertyNames(PSObject source, IList<string> propertyNames)
 {
     PSMemberInfoCollection<PSPropertyInfo> infos = new PSMemberInfoIntegratingCollection<PSPropertyInfo>(source, PSObject.GetPropertyCollection(PSMemberViewTypes.Adapted | PSMemberViewTypes.Extended));
     propertyNames = new Collection<string>();
     foreach (PSPropertyInfo info in infos)
     {
         propertyNames.Add(info.Name);
     }
     return propertyNames;
 }
Beispiel #4
0
        internal IList <string> BuildPropertyNames(PSObject source, IList <string> propertyNames)
        {
            PSMemberInfoCollection <PSPropertyInfo> infos = new PSMemberInfoIntegratingCollection <PSPropertyInfo>(source, PSObject.GetPropertyCollection(PSMemberViewTypes.Adapted | PSMemberViewTypes.Extended));

            propertyNames = new Collection <string>();
            foreach (PSPropertyInfo info in infos)
            {
                propertyNames.Add(info.Name);
            }
            return(propertyNames);
        }
Beispiel #5
0
 private static List<string> GetPropertyNamesFromView(PSObject source, PSMemberViewTypes viewType)
 {
     Collection<CollectionEntry<PSMemberInfo>> memberCollection = PSObject.GetMemberCollection(viewType);
     ReadOnlyPSMemberInfoCollection<PSMemberInfo> infos = new PSMemberInfoIntegratingCollection<PSMemberInfo>(source, memberCollection).Match("*", PSMemberTypes.Properties);
     List<string> list = new List<string>();
     foreach (PSMemberInfo info in infos)
     {
         list.Add(info.Name);
     }
     return list;
 }
        private static List <string> GetPropertyNamesFromView(PSObject source, PSMemberViewTypes viewType)
        {
            Collection <CollectionEntry <PSMemberInfo> >  memberCollection = PSObject.GetMemberCollection(viewType);
            ReadOnlyPSMemberInfoCollection <PSMemberInfo> infos            = new PSMemberInfoIntegratingCollection <PSMemberInfo>(source, memberCollection).Match("*", PSMemberTypes.Properties);
            List <string> list = new List <string>();

            foreach (PSMemberInfo info in infos)
            {
                list.Add(info.Name);
            }
            return(list);
        }
Beispiel #7
0
 public PSMemberSet(string name)
 {
     this.inheritMembers = true;
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     base.name = name;
     this.internalMembers = new PSMemberInfoInternalCollection<PSMemberInfo>();
     this.members = new PSMemberInfoIntegratingCollection<PSMemberInfo>(this, emptyMemberCollection);
     this.properties = new PSMemberInfoIntegratingCollection<PSPropertyInfo>(this, emptyPropertyCollection);
     this.methods = new PSMemberInfoIntegratingCollection<PSMethodInfo>(this, emptyMethodCollection);
 }
Beispiel #8
0
 internal PSMemberSet(string name, PSObject mshObject)
 {
     this.inheritMembers = true;
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     base.name = name;
     if (mshObject == null)
     {
         throw PSTraceSource.NewArgumentNullException("mshObject");
     }
     this.constructorPSObject = mshObject;
     this.internalMembers = mshObject.InstanceMembers;
     this.members = new PSMemberInfoIntegratingCollection<PSMemberInfo>(this, typeMemberCollection);
     this.properties = new PSMemberInfoIntegratingCollection<PSPropertyInfo>(this, typePropertyCollection);
     this.methods = new PSMemberInfoIntegratingCollection<PSMethodInfo>(this, typeMethodCollection);
 }
        private static List<string> GetPropertyNamesFromView(PSObject source, PSMemberViewTypes viewType)
        {
            Collection<CollectionEntry<PSMemberInfo>> memberCollection =
                PSObject.GetMemberCollection(viewType);

            PSMemberInfoIntegratingCollection<PSMemberInfo> membersToSearch =
                new PSMemberInfoIntegratingCollection<PSMemberInfo>(source, memberCollection);

            ReadOnlyPSMemberInfoCollection<PSMemberInfo> matchedMembers =
                membersToSearch.Match("*", PSMemberTypes.Properties);

            List<string> retVal = new List<string>();
            foreach (PSMemberInfo member in matchedMembers)
            {
                retVal.Add(member.Name);
            }
            return retVal;
        }
Beispiel #10
0
 private void AppendPsProperties(PSObject psobj, IDictionary receiver, int depth, bool isCustomObject)
 {
     PSMemberInfoCollection<PSPropertyInfo> infos = new PSMemberInfoIntegratingCollection<PSPropertyInfo>(psobj, isCustomObject ? PSObject.GetPropertyCollection(PSMemberViewTypes.Adapted | PSMemberViewTypes.Extended) : PSObject.GetPropertyCollection(PSMemberViewTypes.Extended));
     foreach (PSPropertyInfo info in infos)
     {
         object obj2 = null;
         try
         {
             obj2 = info.Value;
         }
         catch (Exception exception)
         {
             UtilityCommon.CheckForSevereException(this, exception);
         }
         if (!receiver.Contains(info.Name))
         {
             receiver[info.Name] = this.ProcessValue(obj2, depth + 1);
         }
     }
 }
        private void AppendPsProperties(PSObject psobj, IDictionary receiver, int depth, bool isCustomObject)
        {
            PSMemberInfoCollection <PSPropertyInfo> infos = new PSMemberInfoIntegratingCollection <PSPropertyInfo>(psobj, isCustomObject ? PSObject.GetPropertyCollection(PSMemberViewTypes.Adapted | PSMemberViewTypes.Extended) : PSObject.GetPropertyCollection(PSMemberViewTypes.Extended));

            foreach (PSPropertyInfo info in infos)
            {
                object obj2 = null;
                try
                {
                    obj2 = info.Value;
                }
                catch (Exception exception)
                {
                    UtilityCommon.CheckForSevereException(this, exception);
                }
                if (!receiver.Contains(info.Name))
                {
                    receiver[info.Name] = this.ProcessValue(obj2, depth + 1);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// This method implements the ProcessRecord method for get-member command.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (this.InputObject == null || this.InputObject == AutomationNull.Value)
            {
                return;
            }

            Type baseObjectAsType = null;

            string  typeName;
            Adapter staticAdapter = null;

            if (this.Static == true)
            {
                staticAdapter = PSObject.DotNetStaticAdapter;
                object baseObject = this.InputObject.BaseObject;
                baseObjectAsType = baseObject as System.Type ?? baseObject.GetType();
                typeName         = baseObjectAsType.FullName;
            }
            else
            {
                var typeNames = this.InputObject.InternalTypeNames;
                if (typeNames.Count != 0)
                {
                    typeName = typeNames[0];
                }
                else
                {
                    // This is never used for display.  It is used only as a key to typesAlreadyDisplayed
                    typeName = "<null>";
                }
            }

            if (_typesAlreadyDisplayed.Contains(typeName))
            {
                return;
            }
            else
            {
                _typesAlreadyDisplayed.Add(typeName, string.Empty);
            }

            PSMemberTypes     memberTypeToSearch = MemberType;
            PSMemberViewTypes viewToSearch       = View;

            if (((View & PSMemberViewTypes.Extended) == 0) &&
                (!typeof(PSMemberSet).ToString().Equals(typeName, StringComparison.OrdinalIgnoreCase)))
            {
                // PSMemberSet is an internal memberset and its properties/methods are populated differently.
                // PSMemberSet instance is created to represent PSExtended, PSAdapted, PSBase, PSObject hidden
                // properties. We should honor extended properties for such case.

                // request is to search dotnet or adapted or both members.
                // dotnet,adapted members cannot be Script*,Note*,Code*
                memberTypeToSearch ^= (PSMemberTypes.AliasProperty | PSMemberTypes.CodeMethod | PSMemberTypes.CodeProperty
                                       | PSMemberTypes.MemberSet | PSMemberTypes.NoteProperty | PSMemberTypes.PropertySet | PSMemberTypes.ScriptMethod
                                       | PSMemberTypes.ScriptProperty);
            }

            if (((View & PSMemberViewTypes.Adapted) == 0) && (View & PSMemberViewTypes.Base) == 0)
            {
                // base and adapted are not mentioned in the view so ignore respective properties
                memberTypeToSearch ^= (PSMemberTypes.Property | PSMemberTypes.ParameterizedProperty | PSMemberTypes.Method);
            }

            if (((View & PSMemberViewTypes.Base) == PSMemberViewTypes.Base) &&
                (InputObject.InternalBaseDotNetAdapter == null))
            {
                // the input object don't have a custom adapter..
                // for this case adapted view and base view are the same.
                viewToSearch |= PSMemberViewTypes.Adapted;
            }

            PSMemberInfoCollection <PSMemberInfo> membersToSearch;

            if (this.Static == true)
            {
                membersToSearch = staticAdapter.BaseGetMembers <PSMemberInfo>(baseObjectAsType);
            }
            else
            {
                Collection <CollectionEntry <PSMemberInfo> > memberCollection = PSObject.GetMemberCollection(viewToSearch);
                membersToSearch = new PSMemberInfoIntegratingCollection <PSMemberInfo>(this.InputObject, memberCollection);
            }

            foreach (string nameElement in this.Name)
            {
                ReadOnlyPSMemberInfoCollection <PSMemberInfo> readOnlyMembers;
                readOnlyMembers = membersToSearch.Match(nameElement, memberTypeToSearch, _matchOptions);

                MemberDefinition[] members = new MemberDefinition[readOnlyMembers.Count];
                int resultCount            = 0;
                foreach (PSMemberInfo member in readOnlyMembers)
                {
                    if (!Force)
                    {
                        PSMethod memberAsPSMethod = member as PSMethod;
                        if ((memberAsPSMethod != null) && (memberAsPSMethod.IsSpecial))
                        {
                            continue;
                        }
                    }

                    members[resultCount] = new MemberDefinition(typeName, member.Name, member.MemberType, member.ToString());
                    resultCount++;
                }

                Array.Sort <MemberDefinition>(members, 0, resultCount, new MemberComparer());
                for (int index = 0; index < resultCount; index++)
                {
                    this.WriteObject(members[index]);
                }
            }
        }
Beispiel #13
0
 protected override void ProcessRecord()
 {
     if ((this.InputObject != null) && (this.InputObject != AutomationNull.Value))
     {
         string  fullName;
         Type    type = null;
         Adapter dotNetStaticAdapter = null;
         if (this.Static == 1)
         {
             dotNetStaticAdapter = PSObject.dotNetStaticAdapter;
             object baseObject = this.InputObject.BaseObject;
             type = baseObject as Type;
             if (type == null)
             {
                 type = baseObject.GetType();
             }
             fullName = type.FullName;
         }
         else
         {
             ConsolidatedString internalTypeNames = this.InputObject.InternalTypeNames;
             if (internalTypeNames.Count != 0)
             {
                 fullName = internalTypeNames[0];
             }
             else
             {
                 fullName = "<null>";
             }
         }
         if (!this.typesAlreadyDisplayed.Contains(fullName))
         {
             PSMemberInfoCollection <PSMemberInfo> infos;
             this.typesAlreadyDisplayed.Add(fullName, "");
             PSMemberTypes     memberType = this.memberType;
             PSMemberViewTypes view       = this.view;
             if (((this.view & PSMemberViewTypes.Extended) == 0) && !typeof(PSMemberSet).ToString().Equals(fullName, StringComparison.OrdinalIgnoreCase))
             {
                 memberType ^= PSMemberTypes.MemberSet | PSMemberTypes.ScriptMethod | PSMemberTypes.CodeMethod | PSMemberTypes.PropertySet | PSMemberTypes.ScriptProperty | PSMemberTypes.NoteProperty | PSMemberTypes.CodeProperty | PSMemberTypes.AliasProperty;
             }
             if (((this.view & PSMemberViewTypes.Adapted) == 0) && ((this.view & PSMemberViewTypes.Base) == 0))
             {
                 memberType ^= PSMemberTypes.ParameterizedProperty | PSMemberTypes.Method | PSMemberTypes.Property;
             }
             if (((this.view & PSMemberViewTypes.Base) == PSMemberViewTypes.Base) && (this.InputObject.InternalBaseDotNetAdapter == null))
             {
                 view |= PSMemberViewTypes.Adapted;
             }
             if (this.Static == 1)
             {
                 infos = dotNetStaticAdapter.BaseGetMembers <PSMemberInfo>(type);
             }
             else
             {
                 Collection <CollectionEntry <PSMemberInfo> > memberCollection = PSObject.GetMemberCollection(view);
                 infos = new PSMemberInfoIntegratingCollection <PSMemberInfo>(this.InputObject, memberCollection);
             }
             foreach (string str3 in this.Name)
             {
                 ReadOnlyPSMemberInfoCollection <PSMemberInfo> infos2 = infos.Match(str3, memberType, this.matchOptions);
                 MemberDefinition[] array = new MemberDefinition[infos2.Count];
                 int index = 0;
                 foreach (PSMemberInfo info in infos2)
                 {
                     if (this.Force == 0)
                     {
                         PSMethod method = info as PSMethod;
                         if ((method != null) && method.IsSpecial)
                         {
                             continue;
                         }
                     }
                     array[index] = new MemberDefinition(fullName, info.Name, info.MemberType, info.ToString());
                     index++;
                 }
                 Array.Sort <MemberDefinition>(array, 0, index, new MemberComparer());
                 for (int i = 0; i < index; i++)
                 {
                     base.WriteObject(array[i]);
                 }
             }
         }
     }
 }
        private static List<string> GetPropertyNamesFromView(PSObject source, PSMemberViewTypes viewType)
        {
            Collection<CollectionEntry<PSMemberInfo>> memberCollection =
                PSObject.GetMemberCollection(viewType);

            PSMemberInfoIntegratingCollection<PSMemberInfo> membersToSearch =
                new PSMemberInfoIntegratingCollection<PSMemberInfo>(source, memberCollection);

            ReadOnlyPSMemberInfoCollection<PSMemberInfo> matchedMembers =
                membersToSearch.Match("*", PSMemberTypes.Properties);

            List<string> retVal = new List<string>();
            foreach (PSMemberInfo member in matchedMembers)
            {
                retVal.Add(member.Name);
            }
            return retVal;
        }
Beispiel #15
0
        BuildPropertyNames(PSObject source, IList<string> propertyNames)
        {
            Dbg.Assert(propertyNames == null, "This method should be called only once per cmdlet instance");

            // serialize only Extended and Adapted properties..
            PSMemberInfoCollection<PSPropertyInfo> srcPropertiesToSearch =
                new PSMemberInfoIntegratingCollection<PSPropertyInfo>(source,
                PSObject.GetPropertyCollection(PSMemberViewTypes.Extended | PSMemberViewTypes.Adapted));

            propertyNames = new Collection<string>();
            foreach (PSPropertyInfo prop in srcPropertiesToSearch)
            {
                propertyNames.Add(prop.Name);
            }
            return propertyNames;
        }