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
13 changes: 6 additions & 7 deletions src/Build/Instance/ProjectItemDefinitionInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,15 @@ string IMetadataTable.GetEscapedValue(string specifiedItemType, string name)
/// <returns>The metadata value, or an null if none exists.</returns>
string IMetadataTable.GetEscapedValueIfPresent(string specifiedItemType, string name)
{
if (specifiedItemType == null || String.Equals(_itemType, specifiedItemType, StringComparison.OrdinalIgnoreCase))
if (_metadata == null)
{
ProjectMetadataInstance metadatum = GetMetadata(name);
if (metadatum != null)
{
return metadatum.EvaluatedValueEscaped;
}
return null;
}

return null;
bool matchesItemType = specifiedItemType == null || String.Equals(_itemType, specifiedItemType, StringComparison.OrdinalIgnoreCase);
return matchesItemType && _metadata.TryGetValue(name, out string value)
? value
: null;
}

#endregion
Expand Down
36 changes: 15 additions & 21 deletions src/Build/Instance/ProjectItemInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,19 +1408,18 @@ public string GetMetadataEscaped(string metadataName)
return escapedValue;
}

ProjectMetadataInstance metadatum;
metadatum = GetItemDefinitionMetadata(metadataName);
escapedValue = GetItemDefinitionMetadataEscaped(metadataName);

if (metadatum != null && Expander<ProjectProperty, ProjectItem>.ExpressionMayContainExpandableExpressions(metadatum.EvaluatedValueEscaped))
if (escapedValue != null && Expander<ProjectProperty, ProjectItem>.ExpressionMayContainExpandableExpressions(escapedValue))
{
Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(null, null, new BuiltInMetadataTable(null, this), FileSystems.Default);

// We don't have a location to use, but this is very unlikely to error
return expander.ExpandIntoStringLeaveEscaped(metadatum.EvaluatedValueEscaped, ExpanderOptions.ExpandBuiltInMetadata, ElementLocation.EmptyLocation);
return expander.ExpandIntoStringLeaveEscaped(escapedValue, ExpanderOptions.ExpandBuiltInMetadata, ElementLocation.EmptyLocation);
}
else if (metadatum != null)
else if (escapedValue != null)
{
return metadatum.EvaluatedValueEscaped;
return escapedValue;
}

string value = GetBuiltInMetadataEscaped(metadataName);
Expand Down Expand Up @@ -1802,7 +1801,7 @@ public bool HasMetadata(string name)
{
if ((_directMetadata?.ContainsKey(name) == true) ||
FileUtilities.ItemSpecModifiers.IsItemSpecModifier(name) ||
GetItemDefinitionMetadata(name) != null)
GetItemDefinitionMetadataEscaped(name) != null)
{
return true;
}
Expand Down Expand Up @@ -1921,19 +1920,14 @@ internal void TranslateWithInterning(ITranslator translator, LookasideStringInte
/// </summary>
internal ProjectMetadataInstance GetMetadataObject(string name)
{
ProjectMetadataInstance value = null;

if (_directMetadata != null && _directMetadata.TryGetValue(name, out string escapedValue))
{
value = new ProjectMetadataInstance(name, escapedValue, allowItemSpecModifiers: true);
}

if (value == null)
if (_directMetadata == null || !_directMetadata.TryGetValue(name, out string escapedValue))
{
value = GetItemDefinitionMetadata(name);
escapedValue = GetItemDefinitionMetadataEscaped(name);
}

return value;
return escapedValue != null
? new ProjectMetadataInstance(name, escapedValue, allowItemSpecModifiers: true)
: null;
}

/// <summary>
Expand Down Expand Up @@ -2085,19 +2079,19 @@ private string GetBuiltInMetadataEscaped(string name)
/// Retrieves the named metadata from the item definition, if any.
/// If it is not present, returns null.
/// </summary>
private ProjectMetadataInstance GetItemDefinitionMetadata(string metadataName)
private string GetItemDefinitionMetadataEscaped(string metadataName)
{
// Check any inherited item definition metadata first. It's more like
// direct metadata, but we didn't want to copy the tables.
if (_itemDefinitions != null)
{
for (int i = 0; i < _itemDefinitions.Count; i++)
{
ProjectMetadataInstance metadataFromDefinition = _itemDefinitions[i].GetMetadata(metadataName);
string metadataValue = ((IMetadataTable)_itemDefinitions[i]).GetEscapedValueIfPresent(itemType: null, metadataName);

if (metadataFromDefinition != null)
if (metadataValue != null)
{
return metadataFromDefinition;
return metadataValue;
}
}
}
Expand Down
Loading