Strings->LocalizableStrings, Extensions->ProjectRootElementExtensions, fix long lines, remove empty line
This commit is contained in:
parent
93c30898e4
commit
8b565616a0
5 changed files with 41 additions and 24 deletions
|
@ -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.";
|
|
@ -49,7 +49,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
|
|||
app.OnExecute(() => {
|
||||
if (string.IsNullOrEmpty(projectArgument.Value))
|
||||
{
|
||||
throw new GracefulException(Strings.RequiredArgumentNotPassed, "<Project>");
|
||||
throw new GracefulException(LocalizableStrings.RequiredArgumentNotPassed, "<Project>");
|
||||
}
|
||||
|
||||
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<string> 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;
|
||||
|
|
|
@ -58,7 +58,7 @@ Commands:
|
|||
}
|
||||
else if (args.Length == 1)
|
||||
{
|
||||
Reporter.Error.WriteLine(string.Format(Strings.RequiredArgumentNotPassed, "<command>").Red());
|
||||
Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentNotPassed, "<command>").Red());
|
||||
Reporter.Output.WriteLine(HelpText);
|
||||
return 1;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ Commands:
|
|||
return builtin(args);
|
||||
}
|
||||
|
||||
Reporter.Error.WriteLine(string.Format(Strings.RequiredArgumentIsInvalid, "<command>").Red());
|
||||
Reporter.Error.WriteLine(string.Format(LocalizableStrings.RequiredArgumentIsInvalid, "<command>").Red());
|
||||
Reporter.Output.WriteLine(HelpText);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
public AddP2PCommand()
|
||||
: base("dotnet")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override CommandResult Execute(string args = "")
|
||||
|
|
|
@ -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<ProjectElement> ItemsWithIncludeAndConditionContaining(this ProjectRootElement root, string itemType, string includePattern, string patternInCondition)
|
||||
public static IEnumerable<ProjectElement> 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<ProjectElement> ItemsWithIncludeContaining(this ProjectRootElement root, string itemType, string includePattern)
|
||||
public static IEnumerable<ProjectElement> 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();
|
||||
}
|
Loading…
Reference in a new issue