System.IO.Path.Combine C# (CSharp) Méthode

Combine() public static méthode

public static Combine ( ) : string
Résultat string
        public static string Combine(params string[] paths)
        {
            if (paths == null)
            {
                throw new ArgumentNullException(nameof(paths));
            }
            Contract.EndContractBlock();

            int finalSize = 0;
            int firstComponent = 0;

            // We have two passes, the first calculates how large a buffer to allocate and does some precondition
            // checks on the paths passed in.  The second actually does the combination.

            for (int i = 0; i < paths.Length; i++)
            {
                if (paths[i] == null)
                {
                    throw new ArgumentNullException(nameof(paths));
                }

                if (paths[i].Length == 0)
                {
                    continue;
                }

                PathInternal.CheckInvalidPathChars(paths[i]);

                if (IsPathRooted(paths[i]))
                {
                    firstComponent = i;
                    finalSize = paths[i].Length;
                }
                else
                {
                    finalSize += paths[i].Length;
                }

                char ch = paths[i][paths[i].Length - 1];
                if (!PathInternal.IsDirectoryOrVolumeSeparator(ch))
                    finalSize++;
            }

            StringBuilder finalPath = StringBuilderCache.Acquire(finalSize);

            for (int i = firstComponent; i < paths.Length; i++)
            {
                if (paths[i].Length == 0)
                {
                    continue;
                }

                if (finalPath.Length == 0)
                {
                    finalPath.Append(paths[i]);
                }
                else
                {
                    char ch = finalPath[finalPath.Length - 1];
                    if (!PathInternal.IsDirectoryOrVolumeSeparator(ch))
                    {
                        finalPath.Append(DirectorySeparatorChar);
                    }

                    finalPath.Append(paths[i]);
                }
            }

            return StringBuilderCache.GetStringAndRelease(finalPath);
        }

Same methods

Path::Combine ( string path1, string path2 ) : string
Path::Combine ( string path1, string path2, string path3 ) : string
Path::Combine ( string path1, string path2, string path3, string path4 ) : string

Usage Example

            public LocalMarketDataStorageDrive(LocalMarketDataDrive parent, SecurityId securityId, string fileName, StorageFormats format, IMarketDataDrive drive)
            {
                if (parent == null)
                {
                    throw new ArgumentNullException("parent");
                }

                if (securityId.IsDefault())
                {
                    throw new ArgumentNullException("securityId");
                }

                if (drive == null)
                {
                    throw new ArgumentNullException("drive");
                }

                if (fileName.IsEmpty())
                {
                    throw new ArgumentNullException("fileName");
                }

                _parent                = parent;
                _securityId            = securityId;
                _fileName              = fileName;
                _format                = format;
                _drive                 = drive;
                _fileNameWithExtension = _fileName + GetExtension(_format);

                _datesDict = new Lazy <CachedSynchronizedOrderedDictionary <DateTime, DateTime> >(() =>
                {
                    var retVal = new CachedSynchronizedOrderedDictionary <DateTime, DateTime>();

                    var datesPath = GetDatesCachePath();

                    if (File.Exists(datesPath))
                    {
                        foreach (var date in LoadDates())
                        {
                            retVal.Add(date, date);
                        }
                    }
                    else
                    {
                        var rootDir = Path;

                        var dates = InteropHelper
                                    .GetDirectories(rootDir)
                                    .Where(dir => File.Exists(IOPath.Combine(dir, _fileNameWithExtension)))
                                    .Select(dir => IOPath.GetFileName(dir).ToDateTime(_dateFormat));

                        foreach (var date in dates)
                        {
                            retVal.Add(date, date);
                        }

                        SaveDates(retVal.CachedValues);
                    }

                    return(retVal);
                }).Track();
            }
All Usage Examples Of System.IO.Path::Combine