using dnlib.DotNet;
using System.Text;
namespace ReCodeIt.Utils;
public static class SysTypeExtentions
{
///
/// Returns a string trimmed after any non letter character
///
///
/// Trimmed string if special character found, or the original string
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;
}
///
/// Returns a string trimmed after any non letter character
///
///
/// Trimmed string if special character found, or the original string
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;
}
///
/// Does the property or field name exist in a given list, this applies prefixes and handles capitalization.
///
///
///
/// True if it in the list
public static bool IsFieldOrPropNameInList(this UTF8String str, List list)
{
if (str.Trim().StartsWith("_"))
{
str = str.Replace("_", "");
}
var result = list.Any(item => str.StartsWith(item, StringComparison.CurrentCultureIgnoreCase));
return result;
}
///
/// Does the property or field name exist in a given list, this applies prefixes and handles capitalization.
///
///
///
/// True if it in the list
public static bool IsFieldOrPropNameInList(this string str, List list)
{
if (str.Trim().StartsWith("_"))
{
str = str.Replace("_", "");
}
var result = list.Any(item => str.StartsWith(item, StringComparison.CurrentCultureIgnoreCase));
return result;
}
}