Skip to content

Commit 110b53c

Browse files
Replacing string operations with functions
1 parent da42209 commit 110b53c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Rules/DscExamplesPresent.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public class DscExamplesPresent : IDSCResourceRule
4040
/// <returns>The results of the analysis</returns>
4141
public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName)
4242
{
43-
String fileNameOnly = fileName.Substring(fileName.LastIndexOf("\\", StringComparison.Ordinal) + 1);
44-
String resourceName = fileNameOnly.Substring(0, fileNameOnly.Length - ".psm1".Length);
45-
String examplesQuery = "*" + resourceName + "*";
43+
String fileNameOnly = Path.GetFileName(fileName);
44+
String resourceName = Path.GetFileNameWithoutExtension(fileNameOnly);
45+
String examplesQuery = String.Format("*{0}*", resourceName);
4646
Boolean examplesPresent = false;
47-
String expectedExamplesPath = fileName + "\\..\\..\\..\\Examples";
47+
String expectedExamplesPath = Path.Combine(new String[] {fileName, "..", "..", "..", "Examples"});
4848

4949
// Verify examples are present
5050
if (Directory.Exists(expectedExamplesPath))
@@ -84,9 +84,9 @@ item is TypeDefinitionAst
8484
{
8585
resourceName = dscClass.Name;
8686

87-
String examplesQuery = "*" + resourceName + "*";
87+
String examplesQuery = String.Format("*{0}*", resourceName);
8888
Boolean examplesPresent = false;
89-
String expectedExamplesPath = fileName + "\\..\\Examples";
89+
String expectedExamplesPath = Path.Combine(new String[] {fileName, "..", "Examples"});
9090

9191
// Verify examples are present
9292
if (Directory.Exists(expectedExamplesPath))

0 commit comments

Comments
 (0)