/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.Shared/Extensions/StringExtensions.cs
34 строки
1 KB
Corvin
Code Quality: Use newer syntaxes for ArgumentException handling (#17258)
10 июл 2025, 05:49
Не верифицирован
10 июл 2025, 05:49
6b8a578
Код
Авторство
О чём код?
// Copyright (c) Files Community // Licensed under the MIT License. using System; namespace Files.Shared.Extensions { public static class StringExtensions { /// <summary>Gets the leftmost <paramref name="length" /> characters from a string.</summary> /// <param name="value">The string to retrieve the substring from.</param> /// <param name="length">The number of characters to retrieve.</param> /// <returns>The substring.</returns> public static string Left(this string value, int length) { ArgumentNullException.ThrowIfNull(value); ArgumentOutOfRangeException.ThrowIfLessThan(length, 0); return length > value.Length ? value : value.Substring(0, length); } /// <summary>Gets the rightmost <paramref name="length" /> characters from a string.</summary> /// <param name="value">The string to retrieve the substring from.</param> /// <param name="length">The number of characters to retrieve.</param> /// <returns>The substring.</returns> public static string Right(this string value, int length) { ArgumentNullException.ThrowIfNull(value); ArgumentOutOfRangeException.ThrowIfLessThan(length, 0); return length > value.Length ? value : value[^length..]; } } }