Code/Extensions/TypeLibraryExtensions.cs
using System.Collections.Immutable;
using Sandbox.Internal;

namespace Nodebox.Extensions;

public static class TypeLibraryExtensions {
    extension(TypeLibrary typeLibrary) {
        public bool IsGenericTypeDefinition(Type type) => typeLibrary.GetType(type).TargetType == type;
        public bool IsConstructedGenericType(Type type) => !typeLibrary.IsGenericTypeDefinition(type);

        public IEnumerable<(MethodDescription, Attribute)> GetMethodsWithAttribute(Type attributeType, bool onlyStatic = true) {
            return typeLibrary.GetTypes().SelectMany(x => x.Members).OfType<MethodDescription>().Where(x => x.IsStatic || !onlyStatic).SelectMany(x => x.Attributes.Where(x => x.GetType().IsAssignableTo(attributeType)).Select(y => (x, y))).ToImmutableList();
        }

#pragma warning disable CA1822
        public HashSet<Type> IntrinsicTypes => Sandbox.Internal.TypeLibrary.IntrinsicTypesStatic;
#pragma warning restore CA1822
        public static HashSet<Type> IntrinsicTypesStatic =>
            [
                // System
                typeof(object),
                typeof(char), typeof(string),
                typeof(bool),
                typeof(byte), typeof(sbyte),
                typeof(ushort), typeof(short),
                typeof(uint), typeof(int),
                typeof(ulong), typeof(long),
                typeof(float), typeof(double),
                typeof(Nullable<>),
                typeof(List<>),
                typeof(Dictionary<,>),
                typeof(HashSet<>),
                typeof(Array),
                typeof(ValueTuple<>),
                typeof(ValueTuple<,>),
                typeof(ValueTuple<,,>),
                typeof(ValueTuple<,,,>),
                typeof(ValueTuple<,,,,>),
                typeof(ValueTuple<,,,,,>),
                typeof(ValueTuple<,,,,,,>),
                typeof(ValueTuple<,,,,,,,>),

                typeof(Vector2),
                typeof(Vector3),
                typeof(Vector4),
                typeof(Vector2Int),
                typeof(Vector3Int),

                typeof(Angles),
                typeof(Rotation),
                typeof(Transform),

                typeof(Color),
                typeof(Color.Rgba16),
                typeof(Color32),
                typeof(ColorHsv),

                typeof(Rect),
                typeof(RectInt),

                typeof(Length),
                typeof(Margin),

                typeof(Capsule),
                typeof(Line),
                typeof(Ray),
                typeof(BBox),
                typeof(Sphere),
                typeof(Frustum),

                typeof(TimeSince), typeof(RealTimeSince),
                typeof(TimeUntil), typeof(RealTimeUntil),

                typeof(Curve),
                typeof(CurveRange),

                typeof(RangedFloat),
                typeof(TextFlag),

                typeof(GameObject),
                typeof(Component),
                typeof(GameTransform),

                // Sandbox.UI
                typeof(Sandbox.UI.OverflowMode),
                typeof(Sandbox.UI.Align),
                typeof(Sandbox.UI.PositionMode),
                typeof(Sandbox.UI.FlexDirection),
                typeof(Sandbox.UI.Justify),
                typeof(Sandbox.UI.DisplayMode),
                typeof(Sandbox.UI.PointerEvents),
                typeof(Sandbox.UI.Wrap),
                typeof(Sandbox.UI.TextAlign),
                typeof(Sandbox.UI.TextOverflow),
                typeof(Sandbox.UI.WordBreak),
                typeof(Sandbox.UI.TextTransform),
                typeof(Sandbox.UI.TextSkipInk),
                typeof(Sandbox.UI.TextDecorationStyle),
                typeof(Sandbox.UI.TextDecoration),
                typeof(Sandbox.UI.WhiteSpace),
                typeof(Sandbox.UI.FontStyle),
                typeof(Sandbox.UI.ImageRendering),
                typeof(Sandbox.UI.BorderImageFill),
                typeof(Sandbox.UI.BorderImageRepeat),
                typeof(Sandbox.UI.BackgroundRepeat),
                typeof(Sandbox.UI.MaskMode),
                typeof(Sandbox.UI.MaskScope),
                typeof(Sandbox.UI.FontSmooth),
                typeof(Sandbox.UI.ObjectFit),
                typeof(Sandbox.UI.ObjectFit),
            ];
    }
}