Migrated Documentation library from NetFlow.DocumentationHelper.Library
This commit is contained in:
Regular → Executable
+48
-1
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using OmegaLeo.HelperLib.Shared.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Extensions
|
||||
namespace OmegaLeo.HelperLib.Extensions
|
||||
{
|
||||
[Documentation(nameof(StringExtensions), "Provides extension methods for the string data type.", null,
|
||||
"")]
|
||||
[Changelog("1.2.0", "Fixed root namespace to OmegaLeo.HelperLib.Extensions.", "January 28, 2026")]
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
@@ -10,6 +14,17 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="value"></param>
|
||||
/// <param name="maxChars"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(Truncate),
|
||||
"Truncates the string to a specified maximum number of characters, appending '...' if truncation occurs.",
|
||||
new[]
|
||||
{
|
||||
"value: The string to truncate.",
|
||||
"maxChars: The maximum number of characters allowed before truncation."
|
||||
},
|
||||
@"```cs
|
||||
var longString = ""This is a very long string that needs to be truncated."";
|
||||
var truncatedString = longString.Truncate(20); // truncatedString will be ""This is a very long...""
|
||||
```")]
|
||||
public static string Truncate(this string value, int maxChars)
|
||||
{
|
||||
return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "...";
|
||||
@@ -20,6 +35,13 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(IsNullOrEmpty),
|
||||
"Checks if the string is null or empty.",
|
||||
new[] { "str: The string to check." },
|
||||
@"```cs
|
||||
string myString = """";
|
||||
bool isNullOrEmpty = myString.IsNullOrEmpty(); // isNullOrEmpty will be true
|
||||
```")]
|
||||
public static bool IsNullOrEmpty(this string str)
|
||||
{
|
||||
return String.IsNullOrEmpty(str);
|
||||
@@ -30,6 +52,13 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(IsNotNullOrEmpty),
|
||||
"Checks if the string is not null or empty.",
|
||||
new[] { "str: The string to check." },
|
||||
@"```cs
|
||||
string myString = ""Hello"";
|
||||
bool isNotNullOrEmpty = myString.IsNotNullOrEmpty(); // isNotNullOrEmpty will be true
|
||||
```")]
|
||||
public static bool IsNotNullOrEmpty(this string str)
|
||||
{
|
||||
return !str.IsNullOrEmpty();
|
||||
@@ -41,6 +70,17 @@ namespace GameDevLibrary.Extensions
|
||||
/// <param name="str"></param>
|
||||
/// <param name="search"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(AnyMatch),
|
||||
"Checks if the string matches any of the provided search strings, ignoring case.",
|
||||
new[]
|
||||
{
|
||||
"str: The string to check.",
|
||||
"search: An array of strings to match against."
|
||||
},
|
||||
@"```cs
|
||||
string myString = ""Hello"";
|
||||
bool matches = myString.AnyMatch(""hi"", ""hello"", ""greetings""); // matches will be true
|
||||
```")]
|
||||
public static bool AnyMatch(this string str, params string[] search)
|
||||
{
|
||||
foreach (string s in search)
|
||||
@@ -59,6 +99,13 @@ namespace GameDevLibrary.Extensions
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
[Documentation(nameof(Reverse),
|
||||
"Reverses the characters in the string.",
|
||||
new[] { "str: The string to reverse." },
|
||||
@"```cs
|
||||
string myString = ""Hello"";
|
||||
string reversedString = myString.Reverse(); // reversedString will be ""olleH""
|
||||
```")]
|
||||
public static string Reverse(this string str)
|
||||
{
|
||||
char[] charArray = str.ToCharArray();
|
||||
|
||||
Reference in New Issue
Block a user