Borodar.RainbowFolders.Editor.Settings.RainbowFoldersSettings.GetFolderByPath C# (CSharp) Method

GetFolderByPath() public method

Searches for a folder config that should be applied for the specified path (regardless of the key type). Returns the first occurrence within the settings, if found; null otherwise.
public GetFolderByPath ( string folderPath ) : RainbowFolder
folderPath string
return RainbowFolder
        public RainbowFolder GetFolderByPath(string folderPath)
        {
            if (IsNullOrEmpty(Folders)) return null;

            foreach (var folder in Folders)
            {
                switch (folder.Type)
                {
                    case KeyType.Name:
                        var folderName = Path.GetFileName(folderPath);
                        if (folder.Key.Equals(folderName)) return folder;
                        break;
                    case KeyType.Path:
                        if (folder.Key.Equals(folderPath)) return folder;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            return null;
        }

Usage Example

        public void ShowWithParams(Vector2 position, string[] paths, int pathIndex)
        {
            _paths = paths;
            _settings = RainbowFoldersSettings.Instance;

            var size = paths.Length;
            _existingFolders = new RainbowFolder[size];
            _currentFolder = new RainbowFolder(KeyType.Path, paths[pathIndex]);

            for (var i = 0; i < size; i++)
                _existingFolders[i] = _settings.GetFolderByPath(paths[i]);

            if (_existingFolders[pathIndex] != null)
                _currentFolder.CopyFrom(_existingFolders[pathIndex]);

            var rect = new Rect(position, WINDOW_SIZE);
            Show<RainbowFoldersPopup>(rect);
        }