AssemblyTool/RecodeItLib/Utils/SysTypeExtentions.cs
CJ-SPT d33f1f3c9b
Dnlib refactor
* First compiling build

* fix out path

* fix hollow

* Traditional loops in favor of linq for clarity

* Start refactor

* Refactor part 2

* Rename variable

* Better error reason handling

* Clean up enum

* Refactor part 3

* Use combo boxes in favor of updowns

* Update tooltips

* fix is nested tree view display

* Capitialization

* Refactor part ??

* remove unused methods

* Expanded IsNested Check

* TypeFilter class + Fix CLI bug

* Remove reflection, change IsDerived and IsNested checks

* Remove optional out for IsPublic

* Remove nullable from IsPublic

* fix logger not resetting color

* actually fix it...

* remove redundant if else on IsPublic check

* Add logging to indicate all types have been filtered out

* Default IsPublic to true

* remove duplicate method call

* Refactor logger to be on its own thread

* Multithread remapping and grouped logging for threads

* 5 more filters

* Finish migrating to the new system

* bug fixes

* Add empty string validation to text fields

* re-enable renamer

* restore renamer

* Multi threaded renaming, still broken

* Basis for method renaming

* More renamer work, might get a passing build now?

* Re-enable publicizer

* Rework logging

* re-enable mapping updates

* fix hollow

* Iterate over all types instead of just one to re-link fields

* Add reference list command

---------

Co-authored-by: clodan <clodan@clodan.com>
2024-06-26 14:45:54 -04:00

113 lines
2.9 KiB
C#

using dnlib.DotNet;
using System.Text;
namespace ReCodeIt.Utils;
public static class SysTypeExtentions
{
/// <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;
}
/// <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;
}
/// <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;
}
/// <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 string str, List<string> list)
{
if (str.Trim().StartsWith("_"))
{
str = str.Replace("_", "");
}
var result = list.Any(item => str.StartsWith(item, StringComparison.CurrentCultureIgnoreCase));
return result;
}
}