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