Back to Harmony

Class Traverse

docs/api/HarmonyLib.Traverse.html

2.4.2.013.9 KB
Original Source

Class Traverse

A reflection helper to read and write private elements

Inheritance

System.Object

Traverse

Namespace : HarmonyLib
Assembly : 0Harmony.dll
Syntax
public class Traverse

Constructors

Traverse(Object)

Creates a new traverse instance from an instance

Declaration
public Traverse(object root)
Parameters
TypeNameDescription
System.Objectroot

The object

|

Traverse(Type)

Creates a new traverse instance from a class/type

Declaration
public Traverse(Type type)
Parameters
TypeNameDescription
System.Typetype

The class/type

|

Fields

CopyFields

A default field action that copies fields to fields

Declaration
public static Action<Traverse, Traverse> CopyFields
Field Value
TypeDescription
System.Action<Traverse, Traverse>

Properties

IsField

Checks if the current traverse instance is for a field

Declaration
public bool IsField { get; }
Property Value
TypeDescription
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
TypeDescription
System.Boolean

True if its a property

|

IsWriteable

Checks if the current field or property is writeable

Declaration
public bool IsWriteable { get; }
Property Value
TypeDescription
System.Boolean

True if writing is possible

|

Methods

Create(Object)

Creates a new traverse instance from an instance

Declaration
public static Traverse Create(object root)
Parameters
TypeNameDescription
System.Objectroot

The object

|

Returns
TypeDescription
Traverse

A Traverse instance

|

Create(Type)

Creates a new traverse instance from a class/type

Declaration
public static Traverse Create(Type type)
Parameters
TypeNameDescription
System.Typetype

The class/type

|

Returns
TypeDescription
Traverse

A Traverse instance

|

Create<T>()

Creates a new traverse instance from a class T

Declaration
public static Traverse Create<T>()
Returns
TypeDescription
Traverse

A Traverse instance

|

Type Parameters
NameDescription
T

The class

|

CreateWithType(String)

Creates a new traverse instance from a named type

Declaration
public static Traverse CreateWithType(string name)
Parameters
TypeNameDescription
System.Stringname

The type name, for format see TypeByName(String)

|

Returns
TypeDescription
Traverse

A Traverse instance

|

Field(String)

Moves the current traverse instance to a field

Declaration
public Traverse Field(string name)
Parameters
TypeNameDescription
System.Stringname

The type name

|

Returns
TypeDescription
Traverse

A traverse instance

|

Field<T>(String)

Moves the current traverse instance to a field

Declaration
public Traverse<T> Field<T>(string name)
Parameters
TypeNameDescription
System.Stringname

The type name

|

Returns
TypeDescription
Traverse<T>

A traverse instance

|

Type Parameters
NameDescription
T

The type of the field

|

FieldExists()

Checks if the current traverse instance is for a field

Declaration
public bool FieldExists()
Returns
TypeDescription
System.Boolean

True if its a field

|

Fields()

Gets all fields of the current type

Declaration
public List<string> Fields()
Returns
TypeDescription
System.Collections.Generic.List\

A list of field names

|

GetValue()

Gets the current value

Declaration
public object GetValue()
Returns
TypeDescription
System.Object

The value

|

GetValue(Object[])

Invokes the current method with arguments and returns the result

Declaration
public object GetValue(params object[] arguments)
Parameters
TypeNameDescription
System.Object[]arguments

The method arguments

|

Returns
TypeDescription
System.Object

The value returned by the method

|

GetValue<T>()

Gets the current value

Declaration
public T GetValue<T>()
Returns
TypeDescription
T

The value

|

Type Parameters
NameDescription
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
TypeNameDescription
System.Object[]arguments

The method arguments

|

Returns
TypeDescription
T

The value returned by the method

|

Type Parameters
NameDescription
T

The type of the value

|

GetValueType()

Gets the type of the current field or property

Declaration
public Type GetValueType()
Returns
TypeDescription
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
TypeNameDescription
System.Objectsource

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
TypeNameDescription
System.Objectsource

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
TypeNameDescription
System.Objectsource

Original object

| | System.Object | target |

Target object

| | System.Action\ | 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
TypeNameDescription
System.Objectsource

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
TypeNameDescription
System.Objectsource

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
TypeNameDescription
System.Objectsource

Original object

| | System.Object | target |

Target object

| | System.Action\ | 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
TypeNameDescription
System.Stringname

The name of the method

| | System.Object[] | arguments |

The arguments defining the argument types of the method overload

|

Returns
TypeDescription
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
TypeNameDescription
System.Stringname

The name of the method

| | System.Type[] | paramTypes |

The argument types of the method

| | System.Object[] | arguments |

The arguments for the method

|

Returns
TypeDescription
Traverse

A traverse instance

|

MethodExists()

Checks if the current traverse instance is for a method

Declaration
public bool MethodExists()
Returns
TypeDescription
System.Boolean

True if its a method

|

Methods()

Gets all methods of the current type

Declaration
public List<string> Methods()
Returns
TypeDescription
System.Collections.Generic.List\

A list of method names

|

Properties()

Gets all properties of the current type

Declaration
public List<string> Properties()
Returns
TypeDescription
System.Collections.Generic.List\

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
TypeNameDescription
System.Stringname

The type name

| | System.Object[] | index |

Optional property index

|

Returns
TypeDescription
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
TypeNameDescription
System.Stringname

The type name

| | System.Object[] | index |

Optional property index

|

Returns
TypeDescription
Traverse<T>

A traverse instance

|

Type Parameters
NameDescription
T

The type of the property

|

PropertyExists()

Checks if the current traverse instance is for a property

Declaration
public bool PropertyExists()
Returns
TypeDescription
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
TypeNameDescription
System.Objectvalue

The value

|

Returns
TypeDescription
Traverse

The same traverse instance

|

ToString()

Returns a string that represents the current traverse

Declaration
public override string ToString()
Returns
TypeDescription
System.String

A string representation

|

Overrides

System.Object.ToString()

Type(String)

Moves the current traverse instance to a inner type

Declaration
public Traverse Type(string name)
Parameters
TypeNameDescription
System.Stringname

The type name

|

Returns
TypeDescription
Traverse

A traverse instance

|

TypeExists()

Checks if the current traverse instance is for a type

Declaration
public bool TypeExists()
Returns
TypeDescription
System.Boolean

True if its a type

|