From 8b565616a023cbc294c219b163a36d5a96ddaf1a Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 23 Nov 2016 15:35:01 -0800 Subject: [PATCH] Strings->LocalizableStrings, Extensions->ProjectRootElementExtensions, fix long lines, remove empty line --- .../{Strings.cs => LocalizableStrings.cs} | 2 +- src/dotnet/commands/dotnet-add-p2p/Program.cs | 26 +++++++-------- src/dotnet/commands/dotnet-add/Program.cs | 4 +-- .../Commands/AddP2PCommand.cs | 1 - ...ons.cs => ProjectRootElementExtensions.cs} | 32 +++++++++++++++---- 5 files changed, 41 insertions(+), 24 deletions(-) rename src/dotnet/{Strings.cs => LocalizableStrings.cs} (96%) rename test/dotnet-add-p2p.Tests/{Extensions.cs => ProjectRootElementExtensions.cs} (66%) diff --git a/src/dotnet/Strings.cs b/src/dotnet/LocalizableStrings.cs similarity index 96% rename from src/dotnet/Strings.cs rename to src/dotnet/LocalizableStrings.cs index 484da984b..64ec79d3f 100644 --- a/src/dotnet/Strings.cs +++ b/src/dotnet/LocalizableStrings.cs @@ -4,7 +4,7 @@ using System.Text; namespace Microsoft.DotNet.Tools { - internal static class Strings + internal static class LocalizableStrings { // Arguments parsing public const string RequiredArgumentNotPassed = "Required argument {0} was not passed."; diff --git a/src/dotnet/commands/dotnet-add-p2p/Program.cs b/src/dotnet/commands/dotnet-add-p2p/Program.cs index cc2e50a6d..6a724620d 100644 --- a/src/dotnet/commands/dotnet-add-p2p/Program.cs +++ b/src/dotnet/commands/dotnet-add-p2p/Program.cs @@ -49,7 +49,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference app.OnExecute(() => { if (string.IsNullOrEmpty(projectArgument.Value)) { - throw new GracefulException(Strings.RequiredArgumentNotPassed, ""); + throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, ""); } ProjectRootElement project; @@ -69,7 +69,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference if (app.RemainingArguments.Count == 0) { - throw new GracefulException(Strings.SpecifyAtLeastOneReference); + throw new GracefulException(LocalizableStrings.SpecifyAtLeastOneReference); } List references = app.RemainingArguments; @@ -120,7 +120,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference throw new GracefulException( string.Join( Environment.NewLine, - notExisting.Select((r) => string.Format(Strings.ReferenceDoesNotExist, r)))); + notExisting.Select((r) => string.Format(LocalizableStrings.ReferenceDoesNotExist, r)))); } } @@ -148,13 +148,13 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference { if (!File.Exists(filename)) { - throw new GracefulException(Strings.ProjectDoesNotExist, filename); + throw new GracefulException(LocalizableStrings.ProjectDoesNotExist, filename); } var project = TryOpenProject(filename); if (project == null) { - throw new GracefulException(Strings.ProjectIsInvalid, filename); + throw new GracefulException(LocalizableStrings.ProjectIsInvalid, filename); } return project; @@ -169,36 +169,36 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference } catch (ArgumentException) { - throw new GracefulException(Strings.CouldNotFindProjectOrDirectory, directory); + throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, directory); } if (!dir.Exists) { - throw new GracefulException(Strings.CouldNotFindProjectOrDirectory, directory); + throw new GracefulException(LocalizableStrings.CouldNotFindProjectOrDirectory, directory); } FileInfo[] files = dir.GetFiles("*proj"); if (files.Length == 0) { - throw new GracefulException(Strings.CouldNotFindAnyProjectInDirectory, directory); + throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, directory); } if (files.Length > 1) { - throw new GracefulException(Strings.MoreThanOneProjectInDirectory, directory); + throw new GracefulException(LocalizableStrings.MoreThanOneProjectInDirectory, directory); } FileInfo projectFile = files.First(); if (!projectFile.Exists) { - throw new GracefulException(Strings.CouldNotFindAnyProjectInDirectory, directory); + throw new GracefulException(LocalizableStrings.CouldNotFindAnyProjectInDirectory, directory); } var ret = TryOpenProject(projectFile.FullName); if (ret == null) { - throw new GracefulException(Strings.FoundInvalidProject, projectFile.FullName); + throw new GracefulException(LocalizableStrings.FoundInvalidProject, projectFile.FullName); } return ret; @@ -219,14 +219,14 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference { if (root.HasExistingItemWithCondition(framework, @ref)) { - Reporter.Output.WriteLine(string.Format(Strings.ProjectAlreadyHasAreference, @ref)); + Reporter.Output.WriteLine(string.Format(LocalizableStrings.ProjectAlreadyHasAreference, @ref)); continue; } numberOfAddedReferences++; itemGroup.AppendChild(root.CreateItemElement(ProjectItemElementType, @ref)); - Reporter.Output.WriteLine(string.Format(Strings.ReferenceAddedToTheProject, @ref)); + Reporter.Output.WriteLine(string.Format(LocalizableStrings.ReferenceAddedToTheProject, @ref)); } return numberOfAddedReferences; diff --git a/src/dotnet/commands/dotnet-add/Program.cs b/src/dotnet/commands/dotnet-add/Program.cs index f563c5ee4..78cb27b6b 100644 --- a/src/dotnet/commands/dotnet-add/Program.cs +++ b/src/dotnet/commands/dotnet-add/Program.cs @@ -58,7 +58,7 @@ Commands: } else if (args.Length == 1) { - Reporter.Error.WriteLine(string.Format(Strings.RequiredArgumentNotPassed, "").Red()); + Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentNotPassed, "").Red()); Reporter.Output.WriteLine(HelpText); return 1; } @@ -76,7 +76,7 @@ Commands: return builtin(args); } - Reporter.Error.WriteLine(string.Format(Strings.RequiredArgumentIsInvalid, "").Red()); + Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentIsInvalid, "").Red()); Reporter.Output.WriteLine(HelpText); return 1; } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddP2PCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddP2PCommand.cs index 9a7f2b517..f6d49a7f8 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddP2PCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddP2PCommand.cs @@ -12,7 +12,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities public AddP2PCommand() : base("dotnet") { - } public override CommandResult Execute(string args = "") diff --git a/test/dotnet-add-p2p.Tests/Extensions.cs b/test/dotnet-add-p2p.Tests/ProjectRootElementExtensions.cs similarity index 66% rename from test/dotnet-add-p2p.Tests/Extensions.cs rename to test/dotnet-add-p2p.Tests/ProjectRootElementExtensions.cs index 218e1dbcc..e53609c73 100644 --- a/test/dotnet-add-p2p.Tests/Extensions.cs +++ b/test/dotnet-add-p2p.Tests/ProjectRootElementExtensions.cs @@ -8,9 +8,11 @@ using System.Collections.Generic; namespace Microsoft.DotNet.Cli.Add.P2P.Tests { - internal static class Extensions + internal static class ProjectRootElementExtensions { - public static int NumberOfItemGroupsWithConditionContaining(this ProjectRootElement root, string patternInCondition) + public static int NumberOfItemGroupsWithConditionContaining( + this ProjectRootElement root, + string patternInCondition) { return root.ItemGroups.Count((itemGroup) => itemGroup.Condition.Contains(patternInCondition)); } @@ -20,7 +22,11 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests return root.ItemGroups.Count((ig) => string.IsNullOrEmpty(ig.Condition)); } - public static IEnumerable ItemsWithIncludeAndConditionContaining(this ProjectRootElement root, string itemType, string includePattern, string patternInCondition) + public static IEnumerable ItemsWithIncludeAndConditionContaining( + this ProjectRootElement root, + string itemType, + string includePattern, + string patternInCondition) { return root.Items.Where((it) => { @@ -34,17 +40,29 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests }); } - public static int NumberOfProjectReferencesWithIncludeAndConditionContaining(this ProjectRootElement root, string includePattern, string patternInCondition) + public static int NumberOfProjectReferencesWithIncludeAndConditionContaining( + this ProjectRootElement root, + string includePattern, + string patternInCondition) { - return root.ItemsWithIncludeAndConditionContaining("ProjectReference", includePattern, patternInCondition).Count(); + return root.ItemsWithIncludeAndConditionContaining( + "ProjectReference", + includePattern, + patternInCondition) + .Count(); } - public static IEnumerable ItemsWithIncludeContaining(this ProjectRootElement root, string itemType, string includePattern) + public static IEnumerable ItemsWithIncludeContaining( + this ProjectRootElement root, + string itemType, + string includePattern) { return root.Items.Where((it) => it.ItemType == itemType && it.Include.Contains(includePattern)); } - public static int NumberOfProjectReferencesWithIncludeContaining(this ProjectRootElement root, string includePattern) + public static int NumberOfProjectReferencesWithIncludeContaining( + this ProjectRootElement root, + string includePattern) { return root.ItemsWithIncludeContaining("ProjectReference", includePattern).Count(); }