Skip to content

Add the name of the attribute type into the message when the definition cannot find #12010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
2 changes: 1 addition & 1 deletion src/Tasks.UnitTests/WriteCodeFragment_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ public void MessageDisplayPositionalParameterNameWhenAttributeNotFound()
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.");
engine.AssertLogContains("Could not infer the type of parameter \"_Parameter1\" because the attribute type \"System.TheAttributeCannotFound\" is unknown. The value will be treated as a string.");
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2459,7 +2459,7 @@
<value>Generated by the MSBuild WriteCodeFragment class.</value>
</data>
<data name="WriteCodeFragment.CouldNotInferParameterType" xml:space="preserve">
<value>Could not infer the type of parameter "{0}" because the attribute type is unknown. The value will be treated as a string.</value>
<value>Could not infer the type of parameter "{0}" because the attribute type "{1}" is unknown. The value will be treated as a string.</value>
</data>
<data name="WriteCodeFragment.CouldNotConvertToInferredType" xml:space="preserve">
<value>Could not convert the value for parameter "{0}" to the inferred type "{1}". The value will be treated as a string. {2}</value>
Expand Down
4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Tasks/Resources/xlf/Strings.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/Tasks/WriteCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,17 @@ private bool AddArguments(
value = ConvertParameterValueToInferredType(
constructorParameterTypes[i],
parameter.Value,
parameter.PositionalParameterName);
parameter.PositionalParameterName,
attribute.Name);
}
else
{
// For named parameters, use the type of the property if we can find it.
value = ConvertParameterValueToInferredType(
attributeType.Value?.GetProperty(parameter.Name)?.PropertyType,
parameter.Value,
parameter.Name);
parameter.Name,
attribute.Name);
}

break;
Expand Down Expand Up @@ -565,13 +567,13 @@ private bool TryConvertParameterValue(string typeName, string rawValue, out Code
/// Returns the converted value as a CodeExpression if successful, or the raw value
/// as a CodeExpression if conversion fails. No errors are logged if the conversion fails.
/// </summary>
private CodeExpression ConvertParameterValueToInferredType(Type inferredType, string rawValue, string parameterName)
private CodeExpression ConvertParameterValueToInferredType(Type inferredType, string rawValue, string parameterName, string attributeTypeName)
{
// If we don't know what type the parameter should be, then we
// can't convert the type. We'll just treat is as a string.
if (inferredType is null)
{
Log.LogMessageFromResources("WriteCodeFragment.CouldNotInferParameterType", parameterName);
Log.LogMessageFromResources("WriteCodeFragment.CouldNotInferParameterType", parameterName, attributeTypeName);
return new CodePrimitiveExpression(rawValue);
}

Expand Down