HasIllegalCharacters() static private method

static private HasIllegalCharacters ( string path, bool checkAdditional ) : bool
path string
checkAdditional bool
return bool
示例#1
0
        private void ValidateParameter(string value, string paramName)
        {
            if (value == null)
            {
                throw new ArgumentNullException(paramName, "File name cannot be null.");
            }

            if (value == string.Empty)
            {
                throw new ArgumentException("Empty file name is not legal.", paramName);
            }

            if (value.Trim() == string.Empty)
            {
                throw new ArgumentException("The path is not of a legal form.");
            }

            if (ExtractFileName(value).IndexOfAny(mockPath.GetInvalidFileNameChars()) > -1)
            {
                throw new NotSupportedException("The given path's format is not supported.");
            }

            var filePath = ExtractFilePath(value);

            if (MockPath.HasIllegalCharacters(filePath, false))
            {
                throw new ArgumentException(Properties.Resources.ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION);
            }
        }
        public void IsLegalAbsoluteOrRelative(string path, string paramName)
        {
            if (path == null)
            {
                throw new ArgumentNullException(paramName, "VALUE_CANNOT_BE_NULL");
            }

            if (path == string.Empty)
            {
                throw new ArgumentException("Empty file name is not legal.", paramName);
            }

            if (path.Trim() == string.Empty)
            {
                throw new ArgumentException("THE_PATH_IS_NOT_OF_A_LEGAL_FORM", paramName);
            }

            if (ExtractFileName(path).IndexOfAny(_mockFileDataAccessor.Path.GetInvalidFileNameChars()) > -1)
            {
                throw new ArgumentException("ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION");
            }

            var filePath = ExtractFilePath(path);

            if (MockPath.HasIllegalCharacters(filePath, false))
            {
                throw new ArgumentException("ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION");
            }
        }
        public override DirectoryInfoBase GetParent(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (path.Length == 0)
            {
                throw new ArgumentException(Properties.Resources.PATH_CANNOT_BE_THE_EMPTY_STRING_OR_ALL_WHITESPACE, "path");
            }

            if (MockPath.HasIllegalCharacters(path, false))
            {
                throw new ArgumentException("Path contains invalid path characters.", "path");
            }

            var absolutePath = mockFileDataAccessor.Path.GetFullPath(path);
            var sepAsString  = mockFileDataAccessor.Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture);

            var lastIndex = 0;

            if (absolutePath != sepAsString)
            {
                var startIndex = absolutePath.EndsWith(sepAsString, StringComparison.OrdinalIgnoreCase) ? absolutePath.Length - 1 : absolutePath.Length;
                lastIndex = absolutePath.LastIndexOf(mockFileDataAccessor.Path.DirectorySeparatorChar, startIndex - 1);
                if (lastIndex < 0)
                {
                    return(null);
                }
            }

            var parentPath = absolutePath.Substring(0, lastIndex);

            if (string.IsNullOrEmpty(parentPath))
            {
                return(null);
            }

            var parent = new MockDirectoryInfo(mockFileDataAccessor, parentPath);

            return(parent);
        }
示例#4
0
        public void IsLegalAbsoluteOrRelative(string path, string paramName)
        {
            if (path == null)
            {
                throw new ArgumentNullException(paramName, StringResources.Manager.GetString("VALUE_CANNOT_BE_NULL"));
            }

            if (path == string.Empty)
            {
                throw new ArgumentException("Empty file name is not legal.", paramName);
            }

            if (path.Trim() == string.Empty)
            {
                throw new ArgumentException(StringResources.Manager.GetString("THE_PATH_IS_NOT_OF_A_LEGAL_FORM"), paramName);
            }

            if (!MockUnixSupport.IsUnixPlatform())
            {
                if (!IsValidUseOfVolumeSeparatorChar(path))
                {
                    throw new NotSupportedException(StringResources.Manager.GetString("THE_PATH_IS_NOT_OF_A_LEGAL_FORM"));
                }
            }

            if (ExtractFileName(path).IndexOfAny(_mockFileDataAccessor.Path.GetInvalidFileNameChars()) > -1)
            {
                throw new ArgumentException(StringResources.Manager.GetString("ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION"));
            }

            var filePath = ExtractFilePath(path);

            if (MockPath.HasIllegalCharacters(filePath, false))
            {
                throw new ArgumentException(StringResources.Manager.GetString("ILLEGAL_CHARACTERS_IN_PATH_EXCEPTION"));
            }
        }