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