Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ namespace StringResourceVisualizer
{
public static class StringExtensions
{
/// <summary>
/// Whether a file name is that of a Visual Studio solution file: the .sln format or the newer, XML based, .slnx format.
/// </summary>
public static bool IsSolutionFileName(this string fileName)
{
return !string.IsNullOrEmpty(fileName)
&& (fileName.EndsWith(".sln", StringComparison.InvariantCultureIgnoreCase)
|| fileName.EndsWith(".slnx", StringComparison.InvariantCultureIgnoreCase));
}

public static async Task<int> IndexOfAnyAsync(this string source, params string[] values)
{
try
Expand Down
4 changes: 2 additions & 2 deletions src/StringResVizPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private async Task SetUpRunningDocumentTableEventsAsync(CancellationToken cancel
private void WatchForSolutionOrProjectChanges(string solutionFileName)
{
// It might actually be the project file name if no solution file exists
if (solutionFileName.EndsWith(".sln", StringComparison.InvariantCultureIgnoreCase))
if (solutionFileName.IsSolutionFileName())
{
this.SlnWatcher.Filter = Path.GetFileName(solutionFileName);
this.SlnWatcher.Path = Path.GetDirectoryName(solutionFileName);
Expand Down Expand Up @@ -315,7 +315,7 @@ private async void SlnWatcher_Renamed(object sender, RenamedEventArgs e)
try
{
// Don't want to know about temporary files created during save.
if (e.FullPath.EndsWith(".sln"))
if (e.FullPath.IsSolutionFileName())
{
await this.SetOrUpdateListOfResxFilesAsync(Path.GetDirectoryName(e.FullPath));
}
Expand Down
73 changes: 73 additions & 0 deletions src/StringResourceVisualizer.Tests/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// <copyright file="StringExtensionsTests.cs" company="Matt Lacey">
// Copyright (c) Matt Lacey. All rights reserved.
// </copyright>

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace StringResourceVisualizer.Tests
{
[TestClass]
public class StringExtensionsTests
{
[TestMethod]
public void IsSolutionFileName_Sln()
{
TestIt(@"C:\Source\MyApp\MyApp.sln", true);
}

[TestMethod]
public void IsSolutionFileName_Slnx()
{
TestIt(@"C:\Source\MyApp\MyApp.slnx", true);
}

[TestMethod]
public void IsSolutionFileName_Sln_UpperCase()
{
TestIt(@"C:\Source\MyApp\MyApp.SLN", true);
}

[TestMethod]
public void IsSolutionFileName_Slnx_MixedCase()
{
TestIt(@"C:\Source\MyApp\MyApp.SlnX", true);
}

[TestMethod]
public void IsSolutionFileName_ProjectFile()
{
TestIt(@"C:\Source\MyApp\MyApp.csproj", false);
}

[TestMethod]
public void IsSolutionFileName_SolutionFilter()
{
TestIt(@"C:\Source\MyApp\MyApp.slnf", false);
}

[TestMethod]
public void IsSolutionFileName_ExtensionInTheMiddleOfThePath()
{
TestIt(@"C:\Source\MyApp.sln\readme.txt", false);
}

[TestMethod]
public void IsSolutionFileName_Empty()
{
TestIt(string.Empty, false);
}

[TestMethod]
public void IsSolutionFileName_Null()
{
TestIt(null, false);
}

private void TestIt(string input, bool expected)
{
var actual = input.IsSolutionFileName();

Assert.AreEqual(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ResourceAdornmentManagerTests.cs" />
<Compile Include="StringExtensionsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down