private List <string> ExpandArgumentAsFileList(GenericExpressionNode argumentNode, ConditionEvaluator.IConditionEvaluationState state, bool isFilePath = true) { string argument = argumentNode.GetUnexpandedValue(state); // Fix path before expansion if (isFilePath) { argument = FileUtilities.FixFilePath(argument); } IList <TaskItem> expanded = state.ExpandIntoTaskItems(argument); var expandedCount = expanded.Count; if (expandedCount == 0) { return(null); } var list = new List <string>(capacity: expandedCount); for (var i = 0; i < expandedCount; i++) { var item = expanded[i]; if (state.EvaluationDirectory != null && !Path.IsPathRooted(item.ItemSpec)) { list.Add(Path.GetFullPath(Path.Combine(state.EvaluationDirectory, item.ItemSpec))); } else { list.Add(item.ItemSpec); } } return(list); }
/// <summary> /// Expands properties and items in the argument, and verifies that the result is consistent /// with a scalar parameter type. /// </summary> /// <param name="function">Function name for errors</param> /// <param name="argumentNode">Argument to be expanded</param> /// <returns>Scalar result</returns> private string ExpandArgumentForScalarParameter(string function, GenericExpressionNode argumentNode, ConditionEvaluator.IConditionEvaluationState state) { string argument = argumentNode.GetUnexpandedValue(state); IList <TaskItem> items; items = state.ExpandIntoTaskItems(argument); string expandedValue = String.Empty; if (items.Count == 0) { // Empty argument, that's fine. } else if (items.Count == 1) { expandedValue = items[0].ItemSpec; } else // too many items for the function { // We only allow a single item to be passed into a scalar parameter. ProjectErrorUtilities.ThrowInvalidProject( state.ElementLocation, "CannotPassMultipleItemsIntoScalarFunction", function, argument, state.ExpandIntoString(argument)); } return(expandedValue); }
private IEnumerable <string> ExpandArgumentAsFileList(GenericExpressionNode argumentNode, ConditionEvaluator.IConditionEvaluationState state, bool isFilePath = true) { string argument = argumentNode.GetUnexpandedValue(state); // Fix path before expansion if (isFilePath) { argument = FileUtilities.FixFilePath(argument); } return(state.ExpandIntoTaskItems(argument) .Select(i => state.EvaluationDirectory != null && !Path.IsPathRooted(i.ItemSpec) ? Path.GetFullPath(Path.Combine(state.EvaluationDirectory, i.ItemSpec)) : i.ItemSpec)); }