docs/api/HarmonyLib.Traverse.html
A reflection helper to read and write private elements
System.Object
Traverse
public class Traverse
Creates a new traverse instance from an instance
public Traverse(object root)
| Type | Name | Description |
|---|---|---|
| System.Object | root |
The object
|
Creates a new traverse instance from a class/type
public Traverse(Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
|
A default field action that copies fields to fields
public static Action<Traverse, Traverse> CopyFields
| Type | Description |
|---|---|
| System.Action<Traverse, Traverse> |
Checks if the current traverse instance is for a field
public bool IsField { get; }
| Type | Description |
|---|---|
| System.Boolean |
True if its a field
|
Checks if the current traverse instance is for a property
public bool IsProperty { get; }
| Type | Description |
|---|---|
| System.Boolean |
True if its a property
|
Checks if the current field or property is writeable
public bool IsWriteable { get; }
| Type | Description |
|---|---|
| System.Boolean |
True if writing is possible
|
Creates a new traverse instance from an instance
public static Traverse Create(object root)
| Type | Name | Description |
|---|---|---|
| System.Object | root |
The object
|
| Type | Description |
|---|---|
| Traverse |
A Traverse instance
|
Creates a new traverse instance from a class/type
public static Traverse Create(Type type)
| Type | Name | Description |
|---|---|---|
| System.Type | type |
The class/type
|
| Type | Description |
|---|---|
| Traverse |
A Traverse instance
|
Creates a new traverse instance from a class T
public static Traverse Create<T>()
| Type | Description |
|---|---|
| Traverse |
A Traverse instance
|
| Name | Description |
|---|---|
| T |
The class
|
Creates a new traverse instance from a named type
public static Traverse CreateWithType(string name)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The type name, for format see TypeByName(String)
|
| Type | Description |
|---|---|
| Traverse |
A Traverse instance
|
Moves the current traverse instance to a field
public Traverse Field(string name)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The type name
|
| Type | Description |
|---|---|
| Traverse |
A traverse instance
|
Moves the current traverse instance to a field
public Traverse<T> Field<T>(string name)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The type name
|
| Type | Description |
|---|---|
| Traverse<T> |
A traverse instance
|
| Name | Description |
|---|---|
| T |
The type of the field
|
Checks if the current traverse instance is for a field
public bool FieldExists()
| Type | Description |
|---|---|
| System.Boolean |
True if its a field
|
Gets all fields of the current type
public List<string> Fields()
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of field names
|
Gets the current value
public object GetValue()
| Type | Description |
|---|---|
| System.Object |
The value
|
Invokes the current method with arguments and returns the result
public object GetValue(params object[] arguments)
| Type | Name | Description |
|---|---|---|
| System.Object[] | arguments |
The method arguments
|
| Type | Description |
|---|---|
| System.Object |
The value returned by the method
|
Gets the current value
public T GetValue<T>()
| Type | Description |
|---|---|
| T |
The value
|
| Name | Description |
|---|---|
| T |
The type of the value
|
Invokes the current method with arguments and returns the result
public T GetValue<T>(params object[] arguments)
| Type | Name | Description |
|---|---|---|
| System.Object[] | arguments |
The method arguments
|
| Type | Description |
|---|---|
| T |
The value returned by the method
|
| Name | Description |
|---|---|
| T |
The type of the value
|
Gets the type of the current field or property
public Type GetValueType()
| Type | Description |
|---|---|
| System.Type |
The type
|
Iterates over all fields of the current type and executes a traverse action
public static void IterateFields(object source, Action<Traverse> action)
| Type | Name | Description |
|---|---|---|
| System.Object | source |
Original object
| | System.Action<Traverse> | action |
The action receiving a Traverse instance for each field
|
Iterates over all fields of the current type and executes a traverse action
public static void IterateFields(object source, object target, Action<Traverse, Traverse> action)
| Type | Name | Description |
|---|---|---|
| System.Object | source |
Original object
| | System.Object | target |
Target object
| | System.Action<Traverse, Traverse> | action |
The action receiving a pair of Traverse instances for each field pair
|
Iterates over all fields of the current type and executes a traverse action
public static void IterateFields(object source, object target, Action<string, Traverse, Traverse> action)
| Type | Name | Description |
|---|---|---|
| System.Object | source |
Original object
| | System.Object | target |
Target object
| | System.Action\ | action |
The action receiving a dot path representing the field pair and the Traverse instances
|
Iterates over all properties of the current type and executes a traverse action
public static void IterateProperties(object source, Action<Traverse> action)
| Type | Name | Description |
|---|---|---|
| System.Object | source |
Original object
| | System.Action<Traverse> | action |
The action receiving a Traverse instance for each property
|
Iterates over all properties of the current type and executes a traverse action
public static void IterateProperties(object source, object target, Action<Traverse, Traverse> action)
| Type | Name | Description |
|---|---|---|
| System.Object | source |
Original object
| | System.Object | target |
Target object
| | System.Action<Traverse, Traverse> | action |
The action receiving a pair of Traverse instances for each property pair
|
Iterates over all properties of the current type and executes a traverse action
public static void IterateProperties(object source, object target, Action<string, Traverse, Traverse> action)
| Type | Name | Description |
|---|---|---|
| System.Object | source |
Original object
| | System.Object | target |
Target object
| | System.Action\ | action |
The action receiving a dot path representing the property pair and the Traverse instances
|
Moves the current traverse instance to a method
public Traverse Method(string name, params object[] arguments)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The name of the method
| | System.Object[] | arguments |
The arguments defining the argument types of the method overload
|
| Type | Description |
|---|---|
| Traverse |
A traverse instance
|
Moves the current traverse instance to a method
public Traverse Method(string name, Type[] paramTypes, object[] arguments = null)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The name of the method
| | System.Type[] | paramTypes |
The argument types of the method
| | System.Object[] | arguments |
The arguments for the method
|
| Type | Description |
|---|---|
| Traverse |
A traverse instance
|
Checks if the current traverse instance is for a method
public bool MethodExists()
| Type | Description |
|---|---|
| System.Boolean |
True if its a method
|
Gets all methods of the current type
public List<string> Methods()
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of method names
|
Gets all properties of the current type
public List<string> Properties()
| Type | Description |
|---|---|
| System.Collections.Generic.List\ |
A list of property names
|
Moves the current traverse instance to a property
public Traverse Property(string name, object[] index = null)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The type name
| | System.Object[] | index |
Optional property index
|
| Type | Description |
|---|---|
| Traverse |
A traverse instance
|
Moves the current traverse instance to a field
public Traverse<T> Property<T>(string name, object[] index = null)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The type name
| | System.Object[] | index |
Optional property index
|
| Type | Description |
|---|---|
| Traverse<T> |
A traverse instance
|
| Name | Description |
|---|---|
| T |
The type of the property
|
Checks if the current traverse instance is for a property
public bool PropertyExists()
| Type | Description |
|---|---|
| System.Boolean |
True if its a property
|
Sets a value of the current field or property
public Traverse SetValue(object value)
| Type | Name | Description |
|---|---|---|
| System.Object | value |
The value
|
| Type | Description |
|---|---|
| Traverse |
The same traverse instance
|
Returns a string that represents the current traverse
public override string ToString()
| Type | Description |
|---|---|
| System.String |
A string representation
|
System.Object.ToString()
Moves the current traverse instance to a inner type
public Traverse Type(string name)
| Type | Name | Description |
|---|---|---|
| System.String | name |
The type name
|
| Type | Description |
|---|---|
| Traverse |
A traverse instance
|
Checks if the current traverse instance is for a type
public bool TypeExists()
| Type | Description |
|---|---|
| System.Boolean |
True if its a type
|