Show / Hide Table of Contents

Class Traverse

A reflection helper to read and write private elements

Inheritance
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
Type Name Description
object root

The object

Traverse(Type)

Creates a new traverse instance from a class/type

Declaration
public Traverse(Type type)
Parameters
Type Name Description
Type type

The class/type

Fields

CopyFields

A default field action that copies fields to fields

Declaration
public static Action<Traverse, Traverse> CopyFields
Field Value
Type Description
Action<Traverse, Traverse>

Properties

IsField

Checks if the current traverse instance is for a field

Declaration
public bool IsField { get; }
Property Value
Type Description
bool

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
bool

True if its a property

IsWriteable

Checks if the current field or property is writeable

Declaration
public bool IsWriteable { get; }
Property Value
Type Description
bool

True if writing is possible

Methods

Create(object)

Creates a new traverse instance from an instance

Declaration
public static Traverse Create(object root)
Parameters
Type Name Description
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
Type type

The class/type

Returns
Type Description
Traverse

A Traverse instance

CreateWithType(string)

Creates a new traverse instance from a named type

Declaration
public static Traverse CreateWithType(string name)
Parameters
Type Name Description
string name

The type name, for format see TypeByName(string)

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

Field(string)

Moves the current traverse instance to a field

Declaration
public Traverse Field(string name)
Parameters
Type Name Description
string name

The type name

Returns
Type Description
Traverse

A traverse instance

FieldExists()

Checks if the current traverse instance is for a field

Declaration
public bool FieldExists()
Returns
Type Description
bool

True if its a field

Field<T>(string)

Moves the current traverse instance to a field

Declaration
public Traverse<T> Field<T>(string name)
Parameters
Type Name Description
string name

The type name

Returns
Type Description
Traverse<T>

A traverse instance

Type Parameters
Name Description
T

The type of the field

Fields()

Gets all fields of the current type

Declaration
public List<string> Fields()
Returns
Type Description
List<string>

A list of field names

GetValue()

Gets the current value

Declaration
public object GetValue()
Returns
Type Description
object

The value

GetValue(params object[])

Invokes the current method with arguments and returns the result

Declaration
public object GetValue(params object[] arguments)
Parameters
Type Name Description
object[] arguments

The method arguments

Returns
Type Description
object

The value returned by the method

GetValueType()

Gets the type of the current field or property

Declaration
public Type GetValueType()
Returns
Type Description
Type

The type

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>(params object[])

Invokes the current method with arguments and returns the result

Declaration
public T GetValue<T>(params object[] arguments)
Parameters
Type Name Description
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

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
object source

Original object

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
object source

Original object

object target

Target object

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
object source

Original object

object target

Target object

Action<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
object source

Original object

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
object source

Original object

object target

Target object

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
object source

Original object

object target

Target object

Action<string, Traverse, Traverse> action

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

Declaration
public Traverse Method(string name, params object[] arguments)
Parameters
Type Name Description
string name

The name of the method

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
string name

The name of the method

Type[] paramTypes

The argument types of the method

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
bool

True if its a method

Methods()

Gets all methods of the current type

Declaration
public List<string> Methods()
Returns
Type Description
List<string>

A list of method names

Properties()

Gets all properties of the current type

Declaration
public List<string> Properties()
Returns
Type Description
List<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
string name

The type name

object[] index

Optional property index

Returns
Type Description
Traverse

A traverse instance

PropertyExists()

Checks if the current traverse instance is for a property

Declaration
public bool PropertyExists()
Returns
Type Description
bool

True if its a property

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
string name

The type name

object[] index

Optional property index

Returns
Type Description
Traverse<T>

A traverse instance

Type Parameters
Name Description
T

The type of the property

SetValue(object)

Sets a value of the current field or property

Declaration
public Traverse SetValue(object value)
Parameters
Type Name Description
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
string

A string representation

Overrides
object.ToString()

Type(string)

Moves the current traverse instance to a inner type

Declaration
public Traverse Type(string name)
Parameters
Type Name Description
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
bool

True if its a type

In this article
Back to top Generated by DocFX