Class AttributeReflectionCache
Thread-safe, domain-reload-aware cache for FieldInfo and
MethodInfo instances retrieved via reflection. Used by Scylla's
custom property drawers and attribute processors to avoid expensive repeated
reflection lookups during every OnGUI call in the Inspector.
Inherited Members
Namespace: Scylla.Core.Editor.Attributes
Assembly: ScyllaCore.Editor.dll
Syntax
[InitializeOnLoad]
public static class AttributeReflectionCache
Remarks
Three independent dictionaries are maintained:
- All fields of a type (keyed by Type), populated by GetFields(Type).
- A specific named field (keyed by
FullTypeName.fieldName), populated by GetField(Type, string). - A specific named method (keyed by
FullTypeName.methodName), populated by GetMethod(Type, string).
All three lookups walk the full inheritance hierarchy when the member is not found on the starting type.
The InitializeOnLoad attribute ensures the static constructor
runs on Editor startup and registers ClearCache() with
UnityEditor.AssemblyReloadEvents.beforeAssemblyReload so that stale
reflection handles are discarded before each domain reload caused by script
recompilation.
Methods
ClearCache()
Clears all cached reflection data, forcing subsequent calls to GetFields(Type), GetField(Type, string), and GetMethod(Type, string) to re-query the reflection API.
Declaration
public static void ClearCache()
Remarks
This method is registered with UnityEditor.AssemblyReloadEvents.beforeAssemblyReload and is therefore called automatically before each domain reload so that stale FieldInfo and MethodInfo instances from the previous assembly are not retained. It may also be called manually in unit tests or other Editor tooling that needs a clean reflection state.
GetField(Type, string)
Returns the FieldInfo for the field named fieldName
on type, searching the full inheritance hierarchy if the field is
not declared directly on type. The result (including a null
result for fields that do not exist) is cached to avoid repeated reflection lookups.
Declaration
public static FieldInfo GetField(Type type, string fieldName)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to begin searching. Must not be |
| string | fieldName | The exact name of the field (case-sensitive). If |
Returns
| Type | Description |
|---|---|
| FieldInfo | The FieldInfo for the matching field, or |
GetFields(Type)
Returns all instance fields declared on type (public and non-public),
using the internal cache to avoid repeated reflection calls during Inspector rendering.
The result includes fields from the declared type only, not from base types; use
GetField(Type, string) if you need to search the full inheritance hierarchy.
Declaration
public static FieldInfo[] GetFields(Type type)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type whose instance fields should be retrieved. If |
Returns
| Type | Description |
|---|---|
| FieldInfo[] | An array of FieldInfo objects representing all instance fields on
|
GetMethod(Type, string)
Returns the MethodInfo for the method named methodName
on type, searching the full inheritance hierarchy if the method is
not declared directly on type. The result (including a null
result for methods that do not exist) is cached to avoid repeated reflection lookups.
Declaration
public static MethodInfo GetMethod(Type type, string methodName)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | type | The type to begin searching. Must not be |
| string | methodName | The exact name of the method (case-sensitive). If |
Returns
| Type | Description |
|---|---|
| MethodInfo | The MethodInfo for the first matching method found when walking from
|