Method GenerateValidName
GenerateValidName(string, Func<string, int, string>, Predicate<string>, int)
Generates a valid path name by mutating a base path name.
Declaration
public static string GenerateValidName(string baseName, Func<string, int, string> mutation, Predicate<string> pathValidator, int startIdx = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | The base path. |
| Func<string, int, string> | mutation | A function defining how to mutate the baseName when the pathValidator returns false. |
| Predicate<string> | pathValidator | A function to check the validity of a path, which returns true when valid and false otherwise. |
| int | startIdx | Start index that will be used for mutations |
Returns
| Type | Description |
|---|---|
| string | A valid path based on the baseName. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when no folder path is specified or invalid new folder path is provided. |
GenerateValidName(Func<int, string>, Predicate<string>, int)
Declaration
public static string GenerateValidName(Func<int, string> generator, Predicate<string> pathValidator, int startIdx = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<int, string> | generator | |
| Predicate<string> | pathValidator | |
| int | startIdx |
Returns
| Type | Description |
|---|---|
| string |
GenerateValidName(string, Predicate<string>)
Creates a valid path name by appending a number to a base path name.
Declaration
public static string GenerateValidName(string filePath, Predicate<string> pathValidator)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filePath | The base path. |
| Predicate<string> | pathValidator | A function to validate a path, which returns true when valid and false otherwise. |
Returns
| Type | Description |
|---|---|
| string | A valid path converted from the base path. |
Examples
GenerateValidName("C:\\temp", path => !Directory.Exists(path)); //Returns "C:\\temp (1)" if "C:\\temp" exists
GenerateValidName(string, Predicate<string>, Func<int, string>)
Creates a valid path name by appending a number to a base path name.
Declaration
public static string GenerateValidName(string filePath, Predicate<string> pathValidator, Func<int, string> suffixGenerator)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filePath | The base path. |
| Predicate<string> | pathValidator | A function to validate a path, which returns true when valid and false otherwise. |
| Func<int, string> | suffixGenerator | A function which will be used to generate post-name suffix |
Returns
| Type | Description |
|---|---|
| string | A valid path converted from the base path. |
Examples
GenerateValidName("C:\\temp", path => !Directory.Exists(path)); //Returns "C:\\temp (1)" if "C:\\temp" exists
GenerateValidName(OSPath, Predicate<OSPath>)
Creates a valid path name by appending a number to a base path name.
Declaration
public static OSPath GenerateValidName(OSPath baseName, Predicate<OSPath> pathValidator)
Parameters
| Type | Name | Description |
|---|---|---|
| OSPath | baseName | The base path. |
| Predicate<OSPath> | pathValidator | A function to validate a path, which returns true when valid and false otherwise. |
Returns
| Type | Description |
|---|---|
| OSPath | A valid path converted from the base path. |
Examples
GenerateValidName("C:\\temp", path => !Directory.Exists(path)); //Returns "C:\\temp (1)" if "C:\\temp" exists