mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Save work. * three billion tweaks * Rune-aware parser. * a * all shedded out for the night * a * oogh * Publicizes a lot of common generic commands, so custom toolshed envs can include them. * Implement parsing for all number types. * i think i might implode * a * Tests. * a * Enum parser test. * do u like parsers * oopls * ug fixes * Toolshed is approaching a non-insignificant part of the engine's size. * Pool toolshed's tests, also type tests. * bwa * tests pass :yay: * Update Robust.Shared/CVars.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * how did this not fail tests * awa * many levels of silly --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Robust.Shared.Log;
|
|
|
|
namespace Robust.Shared.Toolshed;
|
|
|
|
// This is for information about commands that can be queried, i.e. return type possibilities.
|
|
|
|
public sealed partial class ToolshedManager
|
|
{
|
|
private Dictionary<Type, HashSet<Type>> _typeCache = new();
|
|
|
|
internal IEnumerable<Type> AllSteppedTypes(Type t, bool allowVariants = true)
|
|
{
|
|
if (_typeCache.TryGetValue(t, out var cache))
|
|
return cache;
|
|
cache = new(AllSteppedTypesInner(t, allowVariants));
|
|
_typeCache[t] = cache;
|
|
|
|
return cache;
|
|
}
|
|
|
|
private IEnumerable<Type> AllSteppedTypesInner(Type t, bool allowVariants)
|
|
{
|
|
Type oldT;
|
|
do
|
|
{
|
|
yield return t;
|
|
if (t == typeof(void))
|
|
yield break;
|
|
|
|
if (t.IsGenericType && allowVariants)
|
|
{
|
|
foreach (var variant in t.GetVariants(this))
|
|
{
|
|
yield return variant;
|
|
}
|
|
}
|
|
|
|
foreach (var @interface in t.GetInterfaces())
|
|
{
|
|
foreach (var innerT in AllSteppedTypes(@interface, allowVariants))
|
|
{
|
|
yield return innerT;
|
|
}
|
|
}
|
|
|
|
if (t.BaseType is { } baseType)
|
|
{
|
|
foreach (var innerT in AllSteppedTypes(baseType, allowVariants))
|
|
{
|
|
yield return innerT;
|
|
}
|
|
}
|
|
|
|
yield return typeof(IEnumerable<>).MakeGenericType(t);
|
|
|
|
oldT = t;
|
|
t = t.StepDownConstraints();
|
|
} while (t != oldT);
|
|
}
|
|
}
|