Game.Reflection.ValueAccessorUtils
Assembly:
Assembly-CSharp (game code / modding assembly)
Namespace:
Game.Reflection
Type:
static class
Base:
System.Object
Summary:
Utility/factory helpers for creating IValueAccessor implementations from reflected members and for creating accessors to elements of Unity.Collections.NativeArray
Fields
None
No instance fields — this is a static utility class.
Properties
None
No properties.
Constructors
None
Static class — no constructors.
Methods
public static IValueAccessor CreateMemberAccessor(IValueAccessor parent, MemberInfo member)
Creates an IValueAccessor for the provided reflected member (FieldInfo, PropertyInfo or MethodInfo). Behavior:- FieldInfo:
- If the field type is NativePerThreadSumInt, it obtains the non-public Count property (get/set methods) of NativePerThreadSumInt and returns a PropertyAccessor constructed around an ObjectAccessor
- Otherwise returns a FieldAccessor(parent, fieldInfo).
- PropertyInfo:
- Obtains the property's get and set methods (including non-public) and returns a PropertyAccessor(parent, getMethod, setMethod).
- MethodInfo:
- Inspects the method parameters and builds an arguments array to match method signature:
- If a parameter named "readOnly" of type bool is present, it populates that slot with true.
- If an out JobHandle (JobHandle& / ref out) parameter is present, it records its index and supplies a default JobHandle value for that slot.
- If multiple JobHandle out parameters are present, logs a warning and returns null.
- If an unknown parameter type/name is encountered, logs a warning and returns null.
- On success returns a GetterWithDepsAccessor(parent, methodInfo, argumentsArray, jobHandleOutIndex).
- Returns null for unsupported member types or invalid parameter shapes.
-
Logs warnings (UnityEngine.Debug.LogWarning) for unknown parameters or multiple JobHandle out parameters.
-
public static IValueAccessor CreateNativeArrayItemAccessor(IValueAccessor accessor, int index)
Creates an accessor for a NativeArray element at the given index if the accessor's valueType is one of the supported NativeArrayinstantiations. Supported element types and the returned accessor types: - NativeArray
-> NativeArrayElementAccessor (wrapping CastAccessor >) - NativeArray
-> NativeArrayElementAccessor - NativeArray
-> NativeArrayElementAccessor - NativeArray
-> NativeArrayElementAccessor - NativeArray
-> NativeArrayElementAccessor - NativeArray
-> NativeArrayElementAccessor - NativeArray
-> NativeArrayElementAccessor - NativeArray
-> NativeArrayElementAccessor - NativeArray
-> NativeArrayElementAccessor - Returns null if the accessor's valueType is not one of the above supported NativeArray types.
Usage Example
// Example: create an accessor for a field or property and for a NativeArray element.
// Assume 'parentAccessor' is an IValueAccessor that yields an instance with the desired member.
using System.Reflection;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Jobs;
// Create accessor for a field named "m_values" on type MyComponent
var type = typeof(MyComponent);
var field = type.GetField("m_values", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
IValueAccessor fieldAccessor = ValueAccessorUtils.CreateMemberAccessor(parentAccessor, field);
// Create accessor for a property named "Count"
var prop = type.GetProperty("Count", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
IValueAccessor propAccessor = ValueAccessorUtils.CreateMemberAccessor(parentAccessor, prop);
// Create accessor for a method (possibly with 'readOnly' and out JobHandle parameter)
var method = type.GetMethod("GetSomething", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
IValueAccessor methodAccessor = ValueAccessorUtils.CreateMemberAccessor(parentAccessor, method);
// If the accessor yields a NativeArray<float3>, create an element accessor at index 5
IValueAccessor nativeArrayAccessor = /* an accessor whose valueType is NativeArray<float3> */;
IValueAccessor elementAccessor = ValueAccessorUtils.CreateNativeArrayItemAccessor(nativeArrayAccessor, 5);
Notes:
- Both factory methods are annotated [CanBeNull] — they return null when the requested accessor can't be created.
- The implementation uses several concrete accessor types (FieldAccessor, PropertyAccessor, GetterWithDepsAccessor, NativeArrayElementAccessor