The Labs \ Source Viewer \ SSCLI \ System.ComponentModel \ SyntaxCheck

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SyntaxCheck.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.ComponentModel
  16. {
  17.     using System;
  18.     using System.Diagnostics;
  19.     using System.IO;
  20.     using System.Runtime.InteropServices;
  21.     using System.Security.Permissions;
  22.    
  23.     /// <internalonly/>
  24.     /// <devdoc>
  25.     /// SyntaxCheck
  26.     /// Helper class to check for path and machine name syntax.
  27.     /// </devdoc>
  28.     [HostProtection(SharedState = true)]
  29.     public static class SyntaxCheck
  30.     {
  31.         /// <devdoc>
  32.         /// Checks the syntax of the machine name (no "\" anywhere in it).
  33.         /// </devdoc>
  34.         /// <internalonly/>
  35.         public static bool CheckMachineName(string value)
  36.         {
  37.             if (value == null)
  38.                 return false;
  39.            
  40.             value = value.Trim();
  41.             if (value.Equals(String.Empty))
  42.                 return false;
  43.            
  44.             // Machine names shouldn't contain any "\"
  45.             return (value.IndexOf('\\') == -1);
  46.         }
  47.        
  48.         /// <devdoc>
  49.         /// Checks the syntax of the path (must start with "\\").
  50.         /// </devdoc>
  51.         /// <internalonly/>
  52.         public static bool CheckPath(string value)
  53.         {
  54.             if (value == null)
  55.                 return false;
  56.            
  57.             value = value.Trim();
  58.             if (value.Equals(String.Empty))
  59.                 return false;
  60.            
  61.             // Path names should start with "\\"
  62.             return value.StartsWith("\\\\");
  63.         }
  64.        
  65.         /// <devdoc>
  66.         /// Checks the syntax of the path (must start with "\" or drive letter "C:").
  67.         /// NOTE: These denote a file or directory path!!
  68.         ///
  69.         /// </devdoc>
  70.         /// <internalonly/>
  71.         public static bool CheckRootedPath(string value)
  72.         {
  73.             if (value == null)
  74.                 return false;
  75.            
  76.             value = value.Trim();
  77.             if (value.Equals(String.Empty))
  78.                 return false;
  79.            
  80.             // Is it rooted?
  81.             return Path.IsPathRooted(value);
  82.         }
  83.     }
  84. }

Developer Fusion