-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileHelper.cs
More file actions
45 lines (39 loc) · 1.59 KB
/
FileHelper.cs
File metadata and controls
45 lines (39 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//*****************************************************************************
//* Code Factory SDK
//* Copyright (c) 2020 CodeFactory, LLC
//*****************************************************************************
using System.IO;
using System.Linq;
namespace CodeFactory.VisualStudio
{
/// <summary>
/// Static helper class that contains functions to support file management with visual studio.
/// </summary>
public static class FileHelper
{
/// <summary>
/// Contains array of invalid characters allowed in a file.
/// </summary>
private static readonly char[] _invalidFileNameCharacter = Path.GetInvalidFileNameChars();
/// <summary>
/// The invalid characters not allowed in a file name.
/// </summary>
public static string InvalidFileNameCharacters => new string(_invalidFileNameCharacter);
/// <summary>
/// Provided file name is checked to determine if it has
/// </summary>
/// <param name="fileName">The filename to be evaluated.</param>
/// <returns>True if invalid characters exists or false if the file does not have invalid characters.</returns>
public static bool ContainsInvalidFileNameCharacter(string fileName)
{
bool result = false;
if (string.IsNullOrEmpty(fileName)) return false;
foreach (var invalidCharacter in _invalidFileNameCharacter)
{
result = fileName.Contains(invalidCharacter);
if (result) break;
}
return result;
}
}
}