internal static List <MshResolvedExpressionParameterAssociation> ExpandParameters(List <MshParameter> parameters, PSObject target) { List <MshResolvedExpressionParameterAssociation> list = new List <MshResolvedExpressionParameterAssociation>(); foreach (MshParameter parameter in parameters) { MshExpression entry = parameter.GetEntry("expression") as MshExpression; foreach (MshExpression expression2 in entry.ResolveNames(target)) { list.Add(new MshResolvedExpressionParameterAssociation(parameter, expression2)); } } return(list); }
internal static List <MshResolvedExpressionParameterAssociation> ExpandParameters(List <MshParameter> parameters, PSObject target) { List <MshResolvedExpressionParameterAssociation> retVal = new List <MshResolvedExpressionParameterAssociation>(); foreach (MshParameter par in parameters) { MshExpression expression = par.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression; List <MshExpression> expandedExpressionList = expression.ResolveNames(target); foreach (MshExpression ex in expandedExpressionList) { retVal.Add(new MshResolvedExpressionParameterAssociation(par, ex)); } } return(retVal); }
/// <summary> /// Retrieve the display name. It looks for a well known property and, /// if not found, it uses some heuristics to get a "close" match /// </summary> /// <param name="target">shell object to process</param> /// <param name="expressionFactory">expression factory to create MshExpression</param> /// <returns>resolved MshExpression; null if no match was found</returns> internal static MshExpression GetDisplayNameExpression(PSObject target, MshExpressionFactory expressionFactory) { // first try to get the expression from the object (types.ps1xml data) MshExpression expressionFromObject = GetDefaultNameExpression(target); if (expressionFromObject != null) { return(expressionFromObject); } // we failed the default display name, let's try some well known names // trying to get something potentially useful string[] knownPatterns = new string[] { "name", "id", "key", "*key", "*name", "*id", }; // go over the patterns, looking for the first match foreach (string pattern in knownPatterns) { MshExpression ex = new MshExpression(pattern); List <MshExpression> exprList = ex.ResolveNames(target); while ((exprList.Count > 0) && ( exprList[0].ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) || exprList[0].ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) || exprList[0].ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase) || exprList[0].ToString().Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase))) { exprList.RemoveAt(0); } if (exprList.Count == 0) { continue; } // if more than one match, just return the first one return(exprList[0]); } // we did not find anything return(null); }
internal static List <MshResolvedExpressionParameterAssociation> ExpandTableParameters(List <MshParameter> parameters, PSObject target) { List <MshResolvedExpressionParameterAssociation> list = new List <MshResolvedExpressionParameterAssociation>(); foreach (MshParameter parameter in parameters) { MshExpression entry = parameter.GetEntry("expression") as MshExpression; List <MshExpression> list2 = entry.ResolveNames(target); if (!entry.HasWildCardCharacters && (list2.Count == 0)) { list.Add(new MshResolvedExpressionParameterAssociation(parameter, entry)); } foreach (MshExpression expression2 in list2) { list.Add(new MshResolvedExpressionParameterAssociation(parameter, expression2)); } } return(list); }
internal static List <MshResolvedExpressionParameterAssociation> ExpandTableParameters(List <MshParameter> parameters, PSObject target) { List <MshResolvedExpressionParameterAssociation> retVal = new List <MshResolvedExpressionParameterAssociation>(); foreach (MshParameter par in parameters) { MshExpression expression = par.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression; List <MshExpression> expandedExpressionList = expression.ResolveNames(target); if (!expression.HasWildCardCharacters && expandedExpressionList.Count == 0) { // we did not find anything, mark as unresolved retVal.Add(new MshResolvedExpressionParameterAssociation(par, expression)); } foreach (MshExpression ex in expandedExpressionList) { retVal.Add(new MshResolvedExpressionParameterAssociation(par, ex)); } } return(retVal); }
/// <summary> /// Retrieve the display name. It looks for a well known property and, /// if not found, it uses some heuristics to get a "close" match /// </summary> /// <param name="target">shell object to process</param> /// <param name="expressionFactory">expression factory to create MshExpression</param> /// <returns>resolved MshExpression; null if no match was found</returns> internal static MshExpression GetDisplayNameExpression(PSObject target, MshExpressionFactory expressionFactory) { // first try to get the expression from the object (types.ps1xml data) MshExpression expressionFromObject = GetDefaultNameExpression(target); if (expressionFromObject != null) { return expressionFromObject; } // we failed the default display name, let's try some well known names // trying to get something potentially useful string[] knownPatterns = new string[] { "name", "id", "key", "*key", "*name", "*id", }; // go over the patterns, looking for the first match foreach (string pattern in knownPatterns) { MshExpression ex = new MshExpression(pattern); List<MshExpression> exprList = ex.ResolveNames(target); while ((exprList.Count > 0) && ( exprList[0].ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) || exprList[0].ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) || exprList[0].ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase) || exprList[0].ToString().Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase))) { exprList.RemoveAt(0); } if (exprList.Count == 0) continue; // if more than one match, just return the first one return exprList[0]; } // we did not find anything return null; }