in src/TaskRunner/Executor.cs [78:170]
private static void SetParameter(object propertyOrParameter, object instance)
{
if (propertyOrParameter is Property property)
{
var propertyInfo = FindPropertyInfo(instance, property.Name, out var flags, out var type);
var stringValue = property.Value;
object value = stringValue;
if (propertyInfo.PropertyType == typeof(bool))
{
value = Convert.ToBoolean(stringValue);
}
else if (propertyInfo.PropertyType == typeof(string[]))
{
if (string.IsNullOrEmpty(stringValue))
{
value = Array.Empty<string>();
}
else
{
value = stringValue.Split(semicolon, StringSplitOptions.RemoveEmptyEntries);
}
}
else if (propertyInfo.PropertyType == typeof(ITaskItem))
{
value = new TaskItem(stringValue);
}
else if (propertyInfo.PropertyType == typeof(ITaskItem[]))
{
if (string.IsNullOrEmpty(stringValue))
{
value = Array.Empty<ITaskItem>();
}
else
{
value = stringValue
.Split(semicolon, StringSplitOptions.RemoveEmptyEntries)
.Select(s => new TaskItem(s))
.ToArray();
}
}
else if (propertyInfo.PropertyType == typeof(int))
{
if (int.TryParse(stringValue, out int intValue))
{
value = intValue;
}
}
SetPropertyValue(instance, property.Name, value);
}
else if (propertyOrParameter is Parameter parameter)
{
var taskItems = GetTaskItems(parameter);
var propertyInfo = FindPropertyInfo(instance, parameter.Name, out var flags, out var type);
object value = null;
if (propertyInfo.PropertyType == typeof(string))
{
string separator = ";";
if (propertyInfo.Name == "SolutionConfigurationContents")
{
separator = Environment.NewLine;
}
value = string.Join(separator, taskItems.Select(t => t.ItemSpec));
}
else if (propertyInfo.PropertyType == typeof(string[]))
{
value = taskItems.Select(t => t.ItemSpec).ToArray();
}
else if (propertyInfo.PropertyType == typeof(ITaskItem))
{
var item = taskItems.First();
foreach (var pair in taskItems.Skip(1).Select(e => e.ItemSpec.TrimStart().Split('=')))
{
item.SetMetadata(pair[0], pair[1]);
}
value = item;
}
else
{
value = taskItems;
}
SetPropertyValue(instance, propertyInfo.Name, value);
}
else
{
throw new NotSupportedException(propertyOrParameter.ToString());
}
}