Пример #1
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;
 }
Пример #2
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);

            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;
        }
Пример #4
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]);
                }
            }
        }
Пример #5
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]);
                 }
             }
         }
     }
 }
Пример #6
0
        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;
        }
Пример #7
0
 private object GetPropertyCollection(PSMemberViewTypes viewTypes)
 {
     return(_getPropertyCollectionMethod.Invoke(null, new object[] { viewTypes }));
 }