Class ReflectionUtils
Provides reflection-based utility methods for mod developers.
public static class ReflectionUtils
- Inheritance
-
ReflectionUtils
- Inherited Members
Methods
GetMethod(Type?, string, BindingFlags)
Recursively searches for a method by name from a class down to the object type.
public static MethodInfo? GetMethod(Type? type, string methodName, BindingFlags bindingFlags)
Parameters
typeTypeThe type you want to recursively search.
methodNamestringThe name of the method you're searching for.
bindingFlagsBindingFlagsThe binding flags to apply during the search.
Returns
- MethodInfo
The method info if found, otherwise null.
GetValueTupleItems(object)
Retrieves the items from the ValueTuple instance.
public static object[]? GetValueTupleItems(this object obj)
Parameters
objobjectThe ValueTuple instance.
Returns
- object[]
The items in the ValueTuple instance.
IsValueTuple(object)
Checks whether the object is a ValueTuple.
public static bool IsValueTuple(this object obj)
Parameters
objobjectThe object type to check.
Returns
- bool
Whether the type is a ValueTuple or not.
TryGetFieldOrProperty(object, string)
Attempts to get a field or property value from an object using reflection. Tries field first, then property. Handles both public and non-public members.
public static object? TryGetFieldOrProperty(object target, string memberName)
Parameters
targetobjectThe target object to get the member from.
memberNamestringThe name of the field or property.
Returns
- object
The value of the member, or
nullif not found or inaccessible.
TrySetFieldOrProperty(object, string, object?)
Attempts to set a field or property value on an object using reflection. Tries field first, then property. Handles both public and non-public members.
public static bool TrySetFieldOrProperty(object target, string memberName, object? value)
Parameters
targetobjectThe target object to set the member on.
memberNamestringThe name of the field or property.
valueobjectThe value to set.
Returns
- bool
trueif the member was successfully set; otherwise,false.