Advanced.Tools
1.1.0
See the version list below for details.
dotnet add package Advanced.Tools --version 1.1.0
NuGet\Install-Package Advanced.Tools -Version 1.1.0
<PackageReference Include="Advanced.Tools" Version="1.1.0" />
paket add Advanced.Tools --version 1.1.0
#r "nuget: Advanced.Tools, 1.1.0"
// Install Advanced.Tools as a Cake Addin #addin nuget:?package=Advanced.Tools&version=1.1.0 // Install Advanced.Tools as a Cake Tool #tool nuget:?package=Advanced.Tools&version=1.1.0
Advanced.Tools Library
Advanced.Tools
is a C# library that provides utility methods and classes for various common tasks, including string validation and user notifications.
Installation
To install the Advanced.Tools
library, add the following to your project:
dotnet add package Advanced.Tools
Usage
Validations
Class
IsLength
Checks if the length of the given string falls within the specified minimum and maximum length constraints.
public static bool IsLength(this string text, int? minLength = null, int? maxLength = null)
Parameters
text
(string): The string to check the length of.minLength
(int, optional): The optional minimum length constraint. If null, no minimum length constraint is applied.maxLength
(int, optional): The optional maximum length constraint. If null, no maximum length constraint is applied.
Returns
bool
: True if the length of the string is greater than 0 and within the specified length constraints, otherwise false.
Example
string example = "Hello";
example.IsLength(minLength: 3, maxLength: 10); // true
example.IsLength(minLength: 6); // false
example.IsLength(maxLength: 4); // false
example.IsLength(); // true
IsCorrectEmail
Validates the given string as an email address using the specified regular expression or a default pattern.
public static bool IsCorrectEmail(this string text, Regex? regex = null)
Parameters
text
(string): The email address string to validate.regex
(Regex, optional): The optional regular expression to use for validation. If null, the default patternEmailRegex
is used.
Returns
bool
: True if the email address matches the provided or default regular expression, otherwise false.
Example
string email = "example@example.com";
bool isValid = email.IsCorrectEmail(); // Returns true if email matches default pattern
Regex customRegex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
bool isValidCustom = email.IsCorrectEmail(customRegex); // Returns true if email matches custom pattern
IsCorrectPhone
Validates the given string as a Russian phone number using the specified regular expression or a default pattern.
public static bool IsCorrectPhone(this string text, Regex? regex = null)
Parameters
text
(string): The phone number string to validate.regex
(Regex, optional): The optional regular expression to use for validation. If null, the default patternPhoneRegex
is used.
Returns
bool
: True if the phone number matches the provided or default regular expression, otherwise false.
Example
string phoneNumber = "+7 123 456-78-90";
bool isValid = phoneNumber.IsCorrectPhone(); // Returns true if phone number matches default pattern
Regex customRegex = new Regex(@"^\+7\d{10}$");
bool isValidCustom = phoneNumber.IsCorrectPhone(customRegex); // Returns true if phone number matches custom pattern
IsCorrectPassword
Validates the given password string against a specified regular expression or a default pattern.
public static bool IsCorrectPassword(this string text, Regex? regex = null)
Parameters
text
(string): The password string to validate.regex
(Regex, optional): . The optional regular expression to use for validation. If null, the default pattern is used.
Returns
bool
: True if the password matches the provided or default regular expression, otherwise false.
Example
string password = "Passw0rd";
bool isValidDefault = password.IsCorrectPassword(); // Returns true if password matches default pattern
Regex customRegex = new Regex(@"^[a-zA-Z0-9]{6,12}$");
bool isValidCustom = password.IsCorrectPassword(customRegex); // Returns true if password matches custom pattern
Hash
Computes the SHA-512 hash of the given string and returns it as a Base64-encoded string.
public static string Hash(this string text)
Parameters
text
(string): The input string to hash.
Returns
string
: A Base64-encoded string representing the SHA-512 hash of the input string.
Example
string example = "HelloWorld";
example.Hash();
Regular Expressions
The library also includes default regular expression patterns for validating email addresses and Russian phone numbers.
public static string PasswordRegex = @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,15}$";
public static string EmailRegex = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
public static string PhoneRegex = @"^(\+7|8)?[\s-]?(\(?\d{3}\)?[\s-]?)?[\d\s-]{7,10}$";
Notify
Class
The Notify
class provides methods for displaying different types of notifications to the user, such as errors, successes, information, and warnings.
Methods
SetGlobalSnackbarPresenter
Sets the global SnackbarPresenter
to be used for displaying notifications.
public static void SetGlobalSnackbarPresenter(SnackbarPresenter snackbarPresenter)
Parameters
snackbarPresenter
(SnackbarPresenter): TheSnackbarPresenter
instance.
HasGlobalSnackbarPresenter
Checks if a global SnackbarPresenter
has been set.
public static bool HasGlobalSnackbarPresenter()
Returns
bool
: True if a globalSnackbarPresenter
has been set, otherwise false.
ShowNotification
Displays a notification with the specified text, title, and type.
public static void ShowNotification(string text, string title, NotificationType type)
Parameters
text
(string): The text content of the notification.title
(string): The title of the notification.type
(NotificationType): The type of the notification (Error, Success, Info, Warning).
Example
Notify.ShowNotification("Operation completed successfully", "Success", Notify.NotificationType.Success);
ShowError
Displays an error notification with the specified text and title.
public static void ShowError(string text, string title)
Parameters
text
(string): The text content of the error notification.title
(string): The title of the error notification.
Example
Notify.ShowError("An error occurred", "Error");
ShowSuccess
Displays a success notification with the specified text and title.
public static void ShowSuccess(string text, string title)
Parameters
text
(string): The text content of the success notification.title
(string): The title of the success notification.
Example
Notify.ShowSuccess("Operation successful", "Success");
ShowInfo
Displays an info notification with the specified text and title.
public static void ShowInfo(string text, string title)
Parameters
text
(string): The text content of the info notification.title
(string): The title of the info notification.
Example
Notify.ShowInfo("Here is some information", "Info");
ShowWarning
Displays a warning notification with the specified text and title.
public static void ShowWarning(string text, string title)
Parameters
text
(string): The text content of the warning notification.title
(string): The title of the warning notification.
Example
Notify.ShowWarning("This is a warning", "Warning");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net8.0-windows was computed. |
-
net6.0-windows7.0
- WPF-UI (>= 3.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.