Delete dead runtime projection reflection caches

This commit is contained in:
Meta Vens 2026-06-16 19:19:05 +01:00
commit 7ed5b4d7db
3 changed files with 41 additions and 96 deletions

View file

@ -32,6 +32,7 @@ RequireMainMenuSettingsCommit(root);
RequirePlayerSettingsEveSurface(root);
RequireMainMenuContinueRunState(root);
RequirePropertiesPanelReadOnlyInspector(root);
RequireNoDeadRuntimeProjectionCaches(root);
RequireRuntimeSimulationTuningCommits(root);
RequireHullConductivityCommitAuthority(root);
RequireInventoryEntityRenameCommitAuthority(root);
@ -869,6 +870,41 @@ static void RequireTypedBehaviorBodyKeys(string root)
}
}
static void RequireNoDeadRuntimeProjectionCaches(string root)
{
var path = Path.Combine(root, "Assets", "Scripts", "ServerShared", "RuntimeProjection", "ReflectionExtensions.cs");
if (!File.Exists(path))
return;
var forbiddenSymbols = new[]
{
"GetAllInterfaceClasses(",
"GetParentTypes(",
"GetAllChildClasses(",
"GetAllGenericChildClasses(",
"IsAssignableToGenericType(",
"GetFullName(",
"InterfaceClasses",
"ParentTypes",
"ChildClasses",
"GenericChildClasses",
"AppDomain.CurrentDomain.GetAssemblies()"
};
var hits = File.ReadLines(path)
.Select((line, index) => new { Line = line, LineNumber = index + 1 })
.Where(line => forbiddenSymbols.Any(symbol => line.Line.Contains(symbol, StringComparison.Ordinal)))
.Select(line => $"Assets/Scripts/ServerShared/RuntimeProjection/ReflectionExtensions.cs:{line.LineNumber}: {line.Line.Trim()}")
.ToArray();
if (hits.Length > 0)
{
throw new InvalidOperationException(
"Dead runtime-projection reflection caches should stay deleted; keep only the live string-formatting helpers: " +
string.Join("; ", hits));
}
}
static void RequireTypedOrbitTaskKeys(string root)
{
var checkedFiles = new[]

View file

@ -1,93 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
public static class ReflectionExtensions
{
private static Dictionary<Type,Type[]> InterfaceClasses = new Dictionary<Type, Type[]>();
public static Type[] GetAllInterfaceClasses(this Type type)
{
if (InterfaceClasses.ContainsKey(type))
return InterfaceClasses[type];
return InterfaceClasses[type] = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(ass => ass.GetTypes()).Where(t => t.IsClass && t.GetInterfaces().Contains(type)).ToArray();
}
private static Dictionary<Type,Type[]> ParentTypes = new Dictionary<Type, Type[]>();
public static Type[] GetParentTypes(this Type type)
{
if (ParentTypes.ContainsKey(type))
return ParentTypes[type];
return ParentTypes[type] = type.GetParents().ToArray();
}
private static IEnumerable<Type> GetParents(this Type type)
{
// is there any base type?
if (type == null)
{
yield break;
}
yield return type;
// return all implemented or inherited interfaces
foreach (var i in type.GetInterfaces())
{
yield return i;
}
// return all inherited types
var currentBaseType = type.BaseType;
while (currentBaseType != null)
{
yield return currentBaseType;
currentBaseType= currentBaseType.BaseType;
}
}
private static Dictionary<Type,Type[]> ChildClasses = new Dictionary<Type, Type[]>();
public static Type[] GetAllChildClasses(this Type type)
{
if (ChildClasses.ContainsKey(type))
return ChildClasses[type];
return ChildClasses[type] = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(ass => ass.GetTypes()).Where(type.IsAssignableFrom).ToArray();
}
private static Dictionary<Type,Type[]> GenericChildClasses = new Dictionary<Type, Type[]>();
public static Type[] GetAllGenericChildClasses(this Type genericType)
{
if (GenericChildClasses.ContainsKey(genericType))
return ChildClasses[genericType];
return ChildClasses[genericType] = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(ass => ass.GetTypes()).Where(type=>type.IsAssignableToGenericType(genericType)).ToArray();
}
public static bool IsAssignableToGenericType(this Type givenType, Type genericType)
{
var interfaceTypes = givenType.GetInterfaces();
foreach (var it in interfaceTypes)
{
if (it.IsGenericType && it.GetGenericTypeDefinition() == genericType)
return true;
}
if (givenType.IsGenericType && givenType.GetGenericTypeDefinition() == genericType)
return true;
Type baseType = givenType.BaseType;
if (baseType == null) return false;
return IsAssignableToGenericType(baseType, genericType);
}
public static string SplitCamelCase( this string str )
{
return Regex.Replace(
@ -107,14 +22,4 @@ public static class ReflectionExtensions
? typeName.Substring(0, typeName.Length - 4)
: typeName).SplitCamelCase();
}
public static string GetFullName(this Type t)
{
if (!t.IsGenericType)
return t.Name.FormatTypeName();
var name = t.Name.FormatTypeName();
return
$"{name.Substring(0, name.LastIndexOf("`"))}{t.GetGenericArguments().Aggregate("<", (aggregate, type) => $"{aggregate}{(aggregate == "<" ? "" : ",")}{GetFullName(type)}")}>";
}
}
}

View file

@ -1728,6 +1728,10 @@ First Aetheria surfaces to publish:
adapter layer. `ItemManager` now reads item rows straight from the shared
typed runtime catalog snapshot instead of rebuilding a duplicate lookup
cache over the same item-key index.
- Done: delete the dead runtime-projection reflection caches. `ReflectionExtensions`
now keeps only the live string-formatting helpers used by `TradeMenu` and
`PropertiesPanel`; it no longer scans loaded assemblies or keeps static
type-cache dictionaries for the old inspector/projection path.
## Verification