示例#1
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);
                    }
                }
            }
        }
示例#2
0
        internal static MshExpressionResult GetDisplayName(
            PSObject target,
            MshExpressionFactory expressionFactory)
        {
            MshExpression displayNameExpression = PSObjectHelper.GetDisplayNameExpression(target, expressionFactory);

            if (displayNameExpression == null)
            {
                return((MshExpressionResult)null);
            }
            List <MshExpressionResult> values = displayNameExpression.GetValues(target);

            return(values.Count == 0 || values[0].Exception != null ? (MshExpressionResult)null : values[0]);
        }
        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);
        }