Show / Hide Table of Contents

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

| Improve this Doc View Source

Traverse(Object)

Creates a new traverse instance from an instance

Declaration
public Traverse(object root)
Parameters
Type Name Description
System.Object root

The object

| Improve this Doc View Source

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 Source

CopyFields

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 Source

IsField

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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 Source

Create(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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

GetValue()

Gets the current value

Declaration
public object GetValue()
Returns
Type Description
System.Object

The value

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

GetValueType()

Gets the type of the current field or property

Declaration
public Type GetValueType()
Returns
Type Description
System.Type

The type

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

ToString()

Returns a string that represents the current traverse

Declaration
public override string ToString()
Returns
Type Description
System.String

A string representation

Overrides
System.Object.ToString()
| Improve this Doc View Source

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

| Improve this Doc View Source

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

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX