internal static List <MshResolvedExpressionParameterAssociation> SetupActiveProperties(List <MshParameter> rawMshParameterList,
                                                                                               PSObject target, MshExpressionFactory expressionFactory)
        {
            // check if we received properties from the command line
            if (rawMshParameterList != null && rawMshParameterList.Count > 0)
            {
                return(AssociationManager.ExpandParameters(rawMshParameterList, target));
            }

            // we did not get any properties:
            //try to get properties from the default property set of the object
            List <MshResolvedExpressionParameterAssociation> activeAssociationList = AssociationManager.ExpandDefaultPropertySet(target, 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(target))
                {
                    activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null,
                                                                                            new MshExpression(RemotingConstants.ComputerNameNoteProperty)));
                }

                return(activeAssociationList);
            }

            // we failed to get anything from the default property set
            // just get all the properties
            activeAssociationList = AssociationManager.ExpandAll(target);
            // Remove PSComputerName and PSShowComputerName from the display as needed.
            AssociationManager.HandleComputerNameProperties(target, activeAssociationList);

            return(activeAssociationList);
        }
Exemplo n.º 2
0
        private void SetUpActiveProperty(PSObject so)
        {
            List <MshParameter> parameters = null;

            if (base.inputParameters != null)
            {
                parameters = base.inputParameters.mshParameterList;
            }
            if ((parameters != null) && (parameters.Count > 0))
            {
                base.activeAssociationList = AssociationManager.ExpandParameters(parameters, so);
            }
            else
            {
                MshExpression displayNameExpression = PSObjectHelper.GetDisplayNameExpression(so, base.expressionFactory);
                if (displayNameExpression != null)
                {
                    base.activeAssociationList = new List <MshResolvedExpressionParameterAssociation>();
                    base.activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, displayNameExpression));
                }
                else
                {
                    base.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, base.expressionFactory);
                    if (base.activeAssociationList.Count <= 0)
                    {
                        base.activeAssociationList = AssociationManager.ExpandAll(so);
                    }
                }
            }
        }
        private void SetUpActiveProperty(PSObject so)
        {
            List <MshParameter> rawMshParameterList = null;

            if (this.inputParameters != null)
            {
                rawMshParameterList = this.inputParameters.mshParameterList;
            }

            // check if we received properties from the command line
            if (rawMshParameterList != null && rawMshParameterList.Count > 0)
            {
                this.activeAssociationList = AssociationManager.ExpandParameters(rawMshParameterList, so);
                return;
            }

            // we did not get any properties:
            //try to get the display property of the object
            MshExpression displayNameExpression = PSObjectHelper.GetDisplayNameExpression(so, this.expressionFactory);

            if (displayNameExpression != null)
            {
                this.activeAssociationList = new List <MshResolvedExpressionParameterAssociation>();
                this.activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, displayNameExpression));
                return;
            }

            // try to get the default property set (we will use the first property)
            this.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, this.expressionFactory);
            if (this.activeAssociationList.Count > 0)
            {
                // we got a valid set of properties from the default property set
                return;
            }

            // we failed to get anything from the default property set
            // just get all the properties
            this.activeAssociationList = AssociationManager.ExpandAll(so);
        }