Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Tasks.UnitTests/WriteCodeFragment_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,26 @@ public void InferredTypeFallsBackToStringWhenTypeConversionFails()
@"[assembly: System.Diagnostics.DebuggableAttribute(true, ""42"")]");
}

/// <summary>
/// If the parameter type cannot be found,
/// then the name of positional parameter should be displayed in the log.
/// </summary>
[Fact]
public void MessageDisplayPositionalParameterNameWhenAttributeNotFound()
{
WriteCodeFragment task = new WriteCodeFragment();
MockEngine engine = new MockEngine(true);
task.BuildEngine = engine;
TaskItem attribute = new TaskItem("System.TheAttributeCannotFound");
attribute.SetMetadata("_Parameter1", "true");
task.AssemblyAttributes = new TaskItem[] { attribute };
task.Language = "C#";
task.OutputDirectory = new TaskItem(Path.GetTempPath());
bool result = task.Execute();

engine.AssertLogContains("Could not infer the type of parameter \"_Parameter1\" because the attribute type is unknown. The value will be treated as a string.");
}

/// <summary>
/// Individual parameters can be typed differently.
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions src/Tasks/WriteCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private string GenerateCode(out string extension)
}

// "_Parameter01" and "_Parameter1" would overwrite each other
orderedParameters[index - 1] = new AttributeParameter { Type = type, Value = value };
orderedParameters[index - 1] = new AttributeParameter { Type = type, Value = value, PositionalParameterName = name };
}
else
{
Expand Down Expand Up @@ -449,7 +449,7 @@ private bool AddArguments(
value = ConvertParameterValueToInferredType(
constructorParameterTypes[i],
parameter.Value,
$"#{i + 1}"); /* back to 1 based */
parameter.PositionalParameterName);
}
else
{
Expand Down Expand Up @@ -624,6 +624,7 @@ private struct AttributeParameter
{
public ParameterType Type { get; init; }
public string Name { get; init; }
public string PositionalParameterName { get; init; }
public string Value { get; init; }
}
}
Expand Down