Repository navigation
Tools
Ilia Petrov-Komotskii edited this page Oct 11, 2026
·
3 revisions
Small static helpers: dates, path strings, enums.
Min / Max of two DateTime values (later / earlier).
using Mane.DotNet;
DateTime start = DateTimeTools.Min(a, b);
DateTime end = DateTimeTools.Max(a, b);RemoveLastComponent strips the last path segment and keeps / vs \ as written. Unlike System.IO.Path on Windows, it does not rewrite separators.
Trailing separators are trimmed first. A root / or \ is kept. No separator in the string → empty string. Null throws.
PathTools.RemoveLastComponent("Assets/Foo/Bar.cs"); // Assets/Foo
PathTools.RemoveLastComponent(@"C:\Game\Data\"); // C:\Game
PathTools.RemoveLastComponent("/"); // /foreach (DamageType t in EnumTools.GetValues<DamageType>())
{
if (t.IsObsolete())
continue;
}
DamageType parsed = "2".ToIntEnum<DamageType>(); // unnamed ints allowed
if ("2".TryParseToIntEnum(out DamageType named, DamageType.None))
Apply(named);-
GetValues<T>()— all enum values. -
IsObsolete()—[Obsolete]on the named field. Combined flags with no matching field name → false. Null throws. -
ToIntEnum<T>(string)—int.Parsethen convert. Unnamed values are OK. Bad input throws. -
TryParseToIntEnum<T>— succeeds only for a defined member (Enum.IsDefined), for any underlying type (byte,long, …). Values that only fit after wrapping (for example257for abyteenum) fail. Otherwise returnsdefaultValue.
openupm add com.manefunction.tools-dotnet