Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
haileymck committed Oct 11, 2023
1 parent 57e1fee commit 6166e48
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ internal sealed class ApplicationFrameworkValueProvider : InterceptingPropertyVa
private const string WinExeOutputType = "WinExe";
private const string NoneItemType = "None";
private const string ApplicationDefinitionItemType = "ApplicationDefinition";
private const string ApplicationFileName = "Application.xaml";

private readonly UnconfiguredProject _project;
private readonly IProjectItemProvider _sourceItemsProvider;
Expand All @@ -52,7 +51,7 @@ public ApplicationFrameworkValueProvider(

public override async Task<string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary<string, string>? dimensionalConditions = null)
{
if (propertyName == ApplicationFramework)
if (StringComparers.PropertyNames.Equals(propertyName, ApplicationFramework))
{
if (await IsWPFApplicationAsync(defaultProperties))
{
Expand All @@ -71,7 +70,7 @@ public ApplicationFrameworkValueProvider(

public override Task<string> OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties)
{
if (propertyName == ApplicationFramework)
if (StringComparers.PropertyNames.Equals(propertyName, ApplicationFramework))
{
return GetPropertyValueAsync(defaultProperties);
}
Expand All @@ -83,7 +82,7 @@ public override Task<string> OnGetEvaluatedPropertyValueAsync(string propertyNam

public override Task<string> OnGetUnevaluatedPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties)
{
if (propertyName == ApplicationFramework)
if (StringComparers.PropertyNames.Equals(propertyName, ApplicationFramework))
{
return GetPropertyValueAsync(defaultProperties);
}
Expand Down Expand Up @@ -170,10 +169,11 @@ private async Task<bool> IsWPFApplicationAsync(IProjectProperties defaultPropert

if (startupObjectValue is not null)
{
string prefix = rootNamespace + ".";
// Use StringComparison.OrdinalIgnoreCase because VB is _not_ case-sensitive
if (startupObjectValue.StartsWith(rootNamespace + ".", StringComparison.OrdinalIgnoreCase))
if (startupObjectValue.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
startupObjectValue = startupObjectValue.Substring((rootNamespace + ".").Length);
startupObjectValue = startupObjectValue.Substring(prefix.Length);
}
await _myAppXmlFileAccessor.SetMainFormAsync(startupObjectValue);
}
Expand Down Expand Up @@ -212,18 +212,21 @@ private async Task<bool> IsWPFApplicationAsync(IProjectProperties defaultPropert
{
// Enabled

string? appXamlFileName = Path.GetFileName(await GetAppXamlRelativeFilePathAsync(create: false));

// Project accessor to remove the ApplicationDefinition property if re-enabled
// Note: this code causes CPS tree validation warning in Debug builds only, but we are ignorning
await _projectAccessor.OpenProjectXmlForWriteAsync(_project, project =>
{
foreach (ProjectItemGroupElement itemGroup in project.ItemGroups.ToList())
foreach (ProjectItemGroupElement itemGroup in project.ItemGroups)
{
foreach (ProjectItemElement item in itemGroup.Items.ToList())
{
if (string.Equals(item.ItemType, ApplicationDefinitionItemType, StringComparisons.ItemTypes))
if (StringComparers.ItemTypes.Equals(item.ItemType, ApplicationDefinitionItemType))
{
itemGroup.RemoveChild(item);
}
else if (string.Equals(item.ItemType, NoneItemType, StringComparisons.ItemTypes) && string.Equals(item.Include, ApplicationFileName, StringComparison.Ordinal))
else if (StringComparers.ItemTypes.Equals(item.ItemType, NoneItemType) && StringComparers.Paths.Equals(item.Include, appXamlFileName))
{
itemGroup.RemoveChild(item);
}
Expand Down

0 comments on commit 6166e48

Please sign in to comment.