AssemblyTool/RecodeItLib/Utils/SysTypeExtentions.cs

113 lines
2.9 KiB
C#
Raw Permalink Normal View History

using dnlib.DotNet;
using System.Text;
2024-06-15 16:21:12 -04:00
2024-06-18 17:35:31 -04:00
namespace ReCodeIt.Utils;
2024-06-15 16:21:12 -04:00
public static class SysTypeExtentions
2024-06-15 16:21:12 -04:00
{
/// <summary>
/// Returns a string trimmed after any non letter character
/// </summary>
/// <param name="str"></param>
/// <returns>Trimmed string if special character found, or the original string</returns>
public static string TrimAfterSpecialChar(this UTF8String str)
{
var sb = new StringBuilder();
var trimChars = new char[] { '`', '[', ']' };
foreach (char c in str.ToString())
{
if (trimChars.Contains(c))
{
}
if (char.IsLetter(c) || char.IsDigit(c))
{
sb.Append(c);
}
else
{
return sb.ToString();
}
}
if (sb.Length > 0)
{
return sb.ToString();
}
return str;
}
2024-06-15 16:21:12 -04:00
/// <summary>
/// Returns a string trimmed after any non letter character
/// </summary>
/// <param name="str"></param>
/// <returns>Trimmed string if special character found, or the original string</returns>
public static string TrimAfterSpecialChar(this string str)
{
var sb = new StringBuilder();
var trimChars = new char[] { '`', '[', ']' };
foreach (char c in str)
{
if (trimChars.Contains(c))
{
}
if (char.IsLetter(c) || char.IsDigit(c))
{
sb.Append(c);
}
else
{
return sb.ToString();
}
}
if (sb.Length > 0)
{
return sb.ToString();
}
return str;
}
2024-06-16 03:43:00 -04:00
/// <summary>
/// Does the property or field name exist in a given list, this applies prefixes and handles capitalization.
/// </summary>
/// <param name="str"></param>
/// <param name="list"></param>
/// <returns>True if it in the list</returns>
public static bool IsFieldOrPropNameInList(this UTF8String str, List<string> list)
{
if (str.Trim().StartsWith("_"))
{
str = str.Replace("_", "");
}
var result = list.Any(item => str.StartsWith(item, StringComparison.CurrentCultureIgnoreCase));
return result;
}
2024-06-16 03:43:00 -04:00
/// <summary>
/// Does the property or field name exist in a given list, this applies prefixes and handles capitalization.
2024-06-16 03:43:00 -04:00
/// </summary>
/// <param name="str"></param>
/// <param name="list"></param>
/// <returns>True if it in the list</returns>
public static bool IsFieldOrPropNameInList(this string str, List<string> list)
{
if (str.Trim().StartsWith("_"))
2024-06-16 03:43:00 -04:00
{
str = str.Replace("_", "");
}
var result = list.Any(item => str.StartsWith(item, StringComparison.CurrentCultureIgnoreCase));
return result;
}
2024-06-15 16:21:12 -04:00
}