Browse documentation

Class Traverse

Namespace
HarmonyLib
Assembly
0Harmony.dll

A reflection helper to read and write private elements

public class Traverse
Inheritance
object
Traverse

Constructors

Traverse(object)

Creates a new traverse instance from an instance

public Traverse(object root)

Parameters

root object

The object

Traverse(Type)

Creates a new traverse instance from a class/type

public Traverse(Type type)

Parameters

type Type

The class/type

Fields

CopyFields

A default field action that copies fields to fields

public static Action<Traverse, Traverse> CopyFields

Field Value

Action<Traverse, Traverse>

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

root object

The object

Returns

Traverse

A Traverse instance

Create(Type)

Creates a new traverse instance from a class/type

public static Traverse Create(Type type)

Parameters

type Type

The class/type

Returns

Traverse

A Traverse instance

CreateWithType(string)

Creates a new traverse instance from a named type

public static Traverse CreateWithType(string name)

Parameters

name string

The type name, for format see TypeByName(string)

Returns

Traverse

A Traverse instance

Create<T>()

Creates a new traverse instance from a class T

public static Traverse Create<T>()

Returns

Traverse

A Traverse instance

Type Parameters

T

The class

Field(string)

Moves the current traverse instance to a field

public Traverse Field(string name)

Parameters

name string

The 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

name string

The type name

Returns

Traverse<T>

A traverse instance

Type Parameters

T

The 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

arguments object[]

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

T

The 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

arguments object[]

The method arguments

Returns

T

The value returned by the method

Type Parameters

T

The 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

source object

Original object

action Action<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

source object

Original object

target object

Target object

action Action<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

source object

Original object

target object

Target object

action Action<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

source object

Original object

action Action<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

source object

Original object

target object

Target object

action Action<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

source object

Original object

target object

Target object

action Action<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

name string

The name of the method

arguments object[]

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

name string

The name of the method

paramTypes Type[]

The argument types of the method

arguments object[]

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

name string

The type name

index object[]

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

name string

The type name

index object[]

Optional property index

Returns

Traverse<T>

A traverse instance

Type Parameters

T

The type of the property

SetValue(object)

Sets a value of the current field or property

public Traverse SetValue(object value)

Parameters

value object

The 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

name string

The 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

Harmony 3 preview

For the stable release, read the 2.x documentation.