示例#1
0
        internal HeaderInfo GenerateHeaderInfo(PSObject input, OutGridViewCommand parentCmdlet)
        {
            HeaderInfo headerInfo = new HeaderInfo();
            List <MshResolvedExpressionParameterAssociation> activeAssociationList;

            // Get properties from the default property set of the object
            activeAssociationList = AssociationManager.ExpandDefaultPropertySet(input, _expressionFactory);
            if (activeAssociationList.Count > 0)
            {
                // we got a valid set of properties from the default property set..add computername for
                // remoteobjects (if available)
                if (PSObjectHelper.ShouldShowComputerNameProperty(input))
                {
                    activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null,
                                                                                            new PSPropertyExpression(RemotingConstants.ComputerNameNoteProperty)));
                }
            }
            else
            {
                // We failed to get anything from the default property set
                activeAssociationList = AssociationManager.ExpandAll(input);
                if (activeAssociationList.Count > 0)
                {
                    // Remove PSComputerName and PSShowComputerName from the display as needed.
                    AssociationManager.HandleComputerNameProperties(input, activeAssociationList);
                    FilterActiveAssociationList(activeAssociationList);
                }
                else
                {
                    // We were unable to retrieve any properties, so we leave an empty list
                    activeAssociationList = new List <MshResolvedExpressionParameterAssociation>();
                }
            }

            for (int k = 0; k < activeAssociationList.Count; k++)
            {
                string propertyName = null;

                MshResolvedExpressionParameterAssociation association = activeAssociationList[k];

                // set the label of the column
                if (association.OriginatingParameter != null)
                {
                    object key = association.OriginatingParameter.GetEntry(FormatParameterDefinitionKeys.LabelEntryKey);
                    if (key != AutomationNull.Value)
                    {
                        propertyName = (string)key;
                    }
                }
                if (propertyName == null)
                {
                    propertyName = association.ResolvedExpression.ToString();
                }
                ColumnInfo columnInfo = new OriginalColumnInfo(propertyName, propertyName, propertyName, parentCmdlet);

                headerInfo.AddColumn(columnInfo);
            }
            return(headerInfo);
        }
示例#2
0
        internal HeaderInfo GenerateHeaderInfo(PSObject input, OutGridViewCommand parentCmdlet)
        {
            HeaderInfo info = new HeaderInfo();
            List <MshResolvedExpressionParameterAssociation> activeAssociationList = AssociationManager.ExpandDefaultPropertySet(input, this.expressionFactory);

            if (activeAssociationList.Count > 0)
            {
                if (PSObjectHelper.ShouldShowComputerNameProperty(input))
                {
                    activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, new MshExpression(RemotingConstants.ComputerNameNoteProperty)));
                }
            }
            else
            {
                activeAssociationList = AssociationManager.ExpandAll(input);
                if (activeAssociationList.Count > 0)
                {
                    AssociationManager.HandleComputerNameProperties(input, activeAssociationList);
                    this.FilterActiveAssociationList(activeAssociationList);
                }
                else
                {
                    activeAssociationList = new List <MshResolvedExpressionParameterAssociation>();
                }
            }
            for (int i = 0; i < activeAssociationList.Count; i++)
            {
                string staleObjectPropertyName = null;
                MshResolvedExpressionParameterAssociation association = activeAssociationList[i];
                if (association.OriginatingParameter != null)
                {
                    object entry = association.OriginatingParameter.GetEntry("label");
                    if (entry != AutomationNull.Value)
                    {
                        staleObjectPropertyName = (string)entry;
                    }
                }
                if (staleObjectPropertyName == null)
                {
                    staleObjectPropertyName = association.ResolvedExpression.ToString();
                }
                Microsoft.PowerShell.Commands.ColumnInfo col = new OriginalColumnInfo(staleObjectPropertyName, staleObjectPropertyName, staleObjectPropertyName, parentCmdlet);
                info.AddColumn(col);
            }
            return(info);
        }