1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System;
6 using System.Diagnostics;
7 using System.IO;
8 using System.Runtime.InteropServices;
9 using System.Security.Permissions;
10 
11 namespace System.ComponentModel
12 {
13     /// <internalonly/>
14     /// <summary>
15     ///     SyntaxCheck
16     ///     Helper class to check for path and machine name syntax.
17     /// </summary>
18     public static class SyntaxCheck
19     {
20         /// <summary>
21         ///     Checks the syntax of the machine name (no "\" anywhere in it).
22         /// </summary>
23         /// <internalonly/>
CheckMachineName(string value)24         public static bool CheckMachineName(string value)
25         {
26             if (value == null)
27                 return false;
28 
29             value = value.Trim();
30             if (value.Equals(String.Empty))
31                 return false;
32 
33             // Machine names shouldn't contain any "\"
34             return (value.IndexOf('\\') == -1);
35         }
36 
37         /// <summary>
38         ///     Checks the syntax of the path (must start with "\\").
39         /// </summary>
40         /// <internalonly/>
CheckPath(string value)41         public static bool CheckPath(string value)
42         {
43             if (value == null)
44                 return false;
45 
46             value = value.Trim();
47             if (value.Equals(String.Empty))
48                 return false;
49 
50             // Path names should start with "\\"
51             return value.StartsWith("\\\\");
52         }
53 
54         /// <summary>
55         ///     Checks the syntax of the path (must start with "\" or drive letter "C:").
56         ///     NOTE:  These denote a file or directory path!!
57         ///
58         /// </summary>
59         /// <internalonly/>
CheckRootedPath(string value)60         public static bool CheckRootedPath(string value)
61         {
62             if (value == null)
63                 return false;
64 
65             value = value.Trim();
66             if (value.Equals(String.Empty))
67                 return false;
68 
69             // Is it rooted?
70             return Path.IsPathRooted(value);
71         }
72     }
73 }
74