Skip to content

Commit

Permalink
fixup formatting to match editorconfig settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Oct 4, 2019
1 parent f0382f9 commit 8c34611
Show file tree
Hide file tree
Showing 34 changed files with 163 additions and 183 deletions.
4 changes: 0 additions & 4 deletions src/MSBuild.Abstractions/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MSBuild.Abstractions
{
Expand Down
72 changes: 31 additions & 41 deletions src/MSBuild.Abstractions/MSBuildHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using MSBuild.Conversion.Facts;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Locator;
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;

using Microsoft.Build.Construction;
using Microsoft.Build.Locator;

using MSBuild.Conversion.Facts;

namespace MSBuild.Abstractions
{
/// <summary>
Expand All @@ -20,7 +21,7 @@ public static class MSBuildHelpers
/// <summary>
/// matches $(name) pattern
/// </summary>
private static readonly Regex DimensionNameInConditionRegex = new Regex(@"^\$\(([^\$\(\)]*)\)$");
private static readonly Regex s_dimensionNameInConditionRegex = new Regex(@"^\$\(([^\$\(\)]*)\)$");

/// <summary>
/// Converts configuration dimensional value vector to a msbuild condition
Expand All @@ -36,10 +37,10 @@ internal static string DimensionalValuePairsToCondition(ImmutableDictionary<stri
return string.Empty; // no condition. Returns empty string to match MSBuild.
}

string left = string.Empty;
string right = string.Empty;
var left = string.Empty;
var right = string.Empty;

foreach (string key in dimensionalValues.Keys)
foreach (var key in dimensionalValues.Keys)
{
if (!string.IsNullOrEmpty(left))
{
Expand All @@ -51,7 +52,7 @@ internal static string DimensionalValuePairsToCondition(ImmutableDictionary<stri
right += dimensionalValues[key];
}

string condition = "'" + left + "'=='" + right + "'";
var condition = "'" + left + "'=='" + right + "'";
return condition;
}

Expand All @@ -65,12 +66,7 @@ internal static string DimensionalValuePairsToCondition(ImmutableDictionary<stri
/// </summary>
public static string GetConfigurationName(string condition)
{
if (ConditionToDimensionValues(condition, out var dimensionValues))
{
return GetConfigurationName(dimensionValues);
}

return "";
return ConditionToDimensionValues(condition, out var dimensionValues) ? GetConfigurationName(dimensionValues) : "";
}

/// <summary>
Expand All @@ -93,7 +89,7 @@ public static bool ConditionToDimensionValues(string condition, out ImmutableDic
return true;
}

int equalPos = condition.IndexOf("==", StringComparison.OrdinalIgnoreCase);
var equalPos = condition.IndexOf("==", StringComparison.OrdinalIgnoreCase);
if (equalPos <= 0)
{
return false;
Expand All @@ -108,27 +104,27 @@ public static bool ConditionToDimensionValues(string condition, out ImmutableDic
return false;
}

string[] dimensionNamesInCondition = left.Split(new char[] { '|' });
string[] dimensionValuesInCondition = right.Split(new char[] { '|' });
var dimensionNamesInCondition = left.Split(new char[] { '|' });
var dimensionValuesInCondition = right.Split(new char[] { '|' });

// number of keys need to match number of values
if (dimensionNamesInCondition.Length == 0 || dimensionNamesInCondition.Length != dimensionValuesInCondition.Length)
{
return false;
}

Dictionary<string, string> parsedDimensionalValues = new Dictionary<string, string>(dimensionNamesInCondition.Length);
var parsedDimensionalValues = new Dictionary<string, string>(dimensionNamesInCondition.Length);

for (int i = 0; i < dimensionNamesInCondition.Length; i++)
for (var i = 0; i < dimensionNamesInCondition.Length; i++)
{
// matches "$(name)" patern.
Match match = DimensionNameInConditionRegex.Match(dimensionNamesInCondition[i]);
var match = s_dimensionNameInConditionRegex.Match(dimensionNamesInCondition[i]);
if (!match.Success)
{
return false;
}

string dimensionName = match.Groups[1].ToString();
var dimensionName = match.Groups[1].ToString();
if (string.IsNullOrEmpty(dimensionName))
{
return false;
Expand All @@ -146,19 +142,13 @@ public static bool ConditionToDimensionValues(string condition, out ImmutableDic
/// </summary>
public static bool FrameworkHasAValueTuple(string tfm)
{
if (tfm is null
return tfm is null
|| tfm.ContainsIgnoreCase(MSBuildFacts.NetstandardPrelude)
|| tfm.ContainsIgnoreCase(MSBuildFacts.NetcoreappPrelude))
{
return false;
}

if (!tfm.StartsWith("net", StringComparison.OrdinalIgnoreCase))
{
return false;
}

return tfm.StartsWith(MSBuildFacts.LowestFrameworkVersionWithSystemValueTuple);
|| tfm.ContainsIgnoreCase(MSBuildFacts.NetcoreappPrelude)
? false
: !tfm.StartsWith("net", StringComparison.OrdinalIgnoreCase)
? false
: tfm.StartsWith(MSBuildFacts.LowestFrameworkVersionWithSystemValueTuple);
}

/// <summary>
Expand Down Expand Up @@ -216,7 +206,7 @@ public static bool HasWPFOrWinForms(ProjectPropertyGroupElement propGroup)
/// <summary>
/// Checks if a given TFM is not .NET Framework.
/// </summary>
public static bool IsNotNetFramework(string tfm) =>
public static bool IsNotNetFramework(string tfm) =>
!tfm.ContainsIgnoreCase(MSBuildFacts.NetcoreappPrelude)
&& !tfm.ContainsIgnoreCase(MSBuildFacts.NetstandardPrelude);

Expand Down Expand Up @@ -248,7 +238,7 @@ public static ProjectItemElement GetPackagesConfigItem(ProjectItemGroupElement p
public static ProjectPropertyGroupElement GetOrCreateTopLevelPropertyGroupWithTFM(IProjectRootElement rootElement) =>
rootElement.PropertyGroups.Single(pg => pg.Properties.Any(p => p.ElementName.Equals(MSBuildFacts.TargetFrameworkNodeName, StringComparison.OrdinalIgnoreCase)))
?? rootElement.AddPropertyGroup();

/// <summary>
/// Finds the item group where PackageReferences are specified. Usually there is only one.
/// </summary>
Expand Down Expand Up @@ -306,12 +296,12 @@ public static bool ArePropertyGroupElementsIdentical(ProjectPropertyGroupElement
/// <returns>true if string is successfuly unquoted</returns>
private static bool UnquoteString(ref string s)
{
if (s.Length < 2 || s[0] != '\'' || s[s.Length - 1] != '\'')
if (s.Length < 2 || s[0] != '\'' || s[^1] != '\'')
{
return false;
}

s = s.Substring(1, s.Length - 2);
s = s[1..^1];
return true;
}

Expand Down Expand Up @@ -368,7 +358,7 @@ private static string GetMSBuildPathIfNotSpecified(string msbuildPath = null)
private static VisualStudioInstance SelectVisualStudioInstance(VisualStudioInstance[] visualStudioInstances)
{
Console.WriteLine("Multiple installs of MSBuild detected please select one:");
for (int i = 0; i < visualStudioInstances.Length; i++)
for (var i = 0; i < visualStudioInstances.Length; i++)
{
Console.WriteLine($"Instance {i + 1}");
Console.WriteLine($" Name: {visualStudioInstances[i].Name}");
Expand All @@ -379,7 +369,7 @@ private static VisualStudioInstance SelectVisualStudioInstance(VisualStudioInsta
while (true)
{
var userResponse = Console.ReadLine();
if (int.TryParse(userResponse, out int instanceNumber) &&
if (int.TryParse(userResponse, out var instanceNumber) &&
instanceNumber > 0 &&
instanceNumber <= visualStudioInstances.Length)
{
Expand Down
7 changes: 4 additions & 3 deletions src/MSBuild.Abstractions/MSBuildProject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Build.Evaluation;

namespace MSBuild.Abstractions
Expand Down Expand Up @@ -56,8 +57,8 @@ public MSBuildProjectProperty(ProjectProperty property)

public string UnevaluatedValue => _property.UnevaluatedValue;

public bool IsDefinedInProject => !_property.IsImported &&
!_property.IsEnvironmentProperty &&
public bool IsDefinedInProject => !_property.IsImported &&
!_property.IsEnvironmentProperty &&
!_property.IsGlobalProperty &&
!_property.IsReservedProperty;
}
Expand Down Expand Up @@ -86,7 +87,7 @@ public MSBuildProjectMetadata(ProjectMetadata projectMetadata)
{
_projectMetadata = projectMetadata;
}

public string Name => _projectMetadata.Name;

public string UnevaluatedValue => _projectMetadata.UnevaluatedValue;
Expand Down
1 change: 1 addition & 0 deletions src/MSBuild.Abstractions/MSBuildProjectRootElement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Xml.Linq;

using Microsoft.Build.Construction;

namespace MSBuild.Abstractions
Expand Down
20 changes: 10 additions & 10 deletions src/MSBuild.Abstractions/MSBuildWorkspace.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using MSBuild.Conversion.Facts;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;

using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;

using MSBuild.Conversion.Facts;

namespace MSBuild.Abstractions
{
public class MSBuildWorkspace
Expand Down Expand Up @@ -126,7 +128,7 @@ void CopyImport(ProjectImportElement import)
{
MSBuildHelpers.AddUseWPF(propGroup);
}

// User is referencing WindowsBase only
if (MSBuildHelpers.IsDesktop(root) && !MSBuildHelpers.HasWPFOrWinForms(propGroup))
{
Expand Down Expand Up @@ -199,11 +201,9 @@ private ProjectStyle GetProjectStyle(IProjectRootElement project)
if (MSBuildFacts.PropsConvertibleToSDK.Contains(firstImportFileName, StringComparer.OrdinalIgnoreCase) &&
MSBuildFacts.TargetsConvertibleToSDK.Contains(lastImportFileName, StringComparer.OrdinalIgnoreCase))
{
if (MSBuildHelpers.IsWPF(project) || MSBuildHelpers.IsWinForms(project) || MSBuildHelpers.IsDesktop(project))
{
return ProjectStyle.WindowsDesktop;
}
return ProjectStyle.Default;
return MSBuildHelpers.IsWPF(project) || MSBuildHelpers.IsWinForms(project) || MSBuildHelpers.IsDesktop(project)
? ProjectStyle.WindowsDesktop
: ProjectStyle.Default;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuild.Abstractions/MSBuildWorkspaceFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ private static string FindMatchingFile(string searchBase, Func<string, IEnumerab
: null;
}
}
}
}
7 changes: 1 addition & 6 deletions src/MSBuild.Abstractions/MSBuildWorkspaceItem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace MSBuild.Abstractions
namespace MSBuild.Abstractions
{
public class MSBuildWorkspaceItem
{
Expand Down
1 change: 1 addition & 0 deletions src/MSBuild.Abstractions/MSBuildWorkspaceLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Immutable;
using System.IO;
using System.Linq;

using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;

Expand Down
8 changes: 4 additions & 4 deletions src/MSBuild.Abstractions/MsBuildExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.Build.Construction;

using System;
using System;
using System.Reflection;
using System.Xml;

using Microsoft.Build.Construction;

namespace MSBuild.Abstractions
{
public static class MsBuildExtensions
Expand Down Expand Up @@ -32,7 +32,7 @@ static object GetPropertyValue(object obj, string propertyName)

static PropertyInfo GetPropertyInfo(Type type, string propertyName)
{
PropertyInfo propInfo = null;
PropertyInfo propInfo;
do
{
propInfo = type.GetProperty(propertyName,
Expand Down
15 changes: 7 additions & 8 deletions src/MSBuild.Abstractions/NugetHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text.Json;
Expand All @@ -9,22 +8,22 @@ namespace MSBuild.Abstractions
{
public static class NugetHelpers
{
private const string searchUrl = "https://api-v2v3search-0.nuget.org/query?q={0}&prerelease=false&semVerLevel=2.0.0&take=1";
private const string SearchUrl = "https://api-v2v3search-0.nuget.org/query?q={0}&prerelease=false&semVerLevel=2.0.0&take=1";

private static readonly Dictionary<string, string> packageToVersionCache = new Dictionary<string, string>();
private static readonly HttpClient httpClient = new HttpClient();
private static readonly Dictionary<string, string> s_packageToVersionCache = new Dictionary<string, string>();
private static readonly HttpClient s_httpClient = new HttpClient();

public static async ValueTask<string> GetLatestVersionForPackageNameAsync(string packageName)
{
if(packageToVersionCache.TryGetValue(packageName, out var version))
if (s_packageToVersionCache.TryGetValue(packageName, out var version))
{
return version;
}

var response = await httpClient.GetAsync(string.Format(searchUrl, packageName));
var response = await s_httpClient.GetAsync(string.Format(SearchUrl, packageName));
var result = await response.Content.ReadAsStreamAsync();
version = GetVersionFromQueryResponse(result);
packageToVersionCache[packageName] = version;
s_packageToVersionCache[packageName] = version;
return version;

static string GetVersionFromQueryResponse(Stream result)
Expand Down
18 changes: 10 additions & 8 deletions src/MSBuild.Abstractions/ProjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using MSBuild.Conversion.Facts;
using Newtonsoft.Json.Linq;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using MSBuild.Conversion.Facts;

using Newtonsoft.Json.Linq;

namespace MSBuild.Abstractions
{
public static class ProjectExtensions
Expand Down Expand Up @@ -72,15 +74,15 @@ public static string GetTargetFramework(this IProject project)

private static string GetTargetFrameworkFromProjectJson(IProject project)
{
string projectFolder = project.GetPropertyValue("MSBuildProjectDirectory");
string projectJsonPath = Path.Combine(projectFolder, "project.json");
var projectFolder = project.GetPropertyValue("MSBuildProjectDirectory");
var projectJsonPath = Path.Combine(projectFolder, "project.json");

string projectJsonContents = File.ReadAllText(projectJsonPath);
var projectJsonContents = File.ReadAllText(projectJsonPath);

JObject json = JObject.Parse(projectJsonContents);
var json = JObject.Parse(projectJsonContents);

var frameworks = json["frameworks"];
string tf = ((JProperty)frameworks.Single()).Name;
var tf = ((JProperty)frameworks.Single()).Name;
return tf;
}
}
Expand Down
Loading

0 comments on commit 8c34611

Please sign in to comment.