# Reflection

Methods which can help you to call private methods, get and set values to/from private fields.

Fields
Methods

No fields

CallMethod
CallStaticMethod
GetField
SetField

# Constructors

No constructors


# Fields

No fields


# Methods

# CallMethod(this o, methodName, params args): object

Call private method

Parameter Type Optional Description
o this object No Ojbect, from which you want to call method
methodName string No Method name
args params object[] No Method arguments

Returns: object

Examples:

using ReflectionUtility;
//...
//Adding spawn effect to 'MapBox.instance.stackEffects' calling private method 'startSpawnEffect' with arguments 'newUnit.currentTile' and 'spawn'
MapBox.instance.stackEffects.CallMethod("startSpawnEffect", newUnit.currentTile, "spawn");
//...
//...
//Adding spawn effect to 'MapBox.instance.stackEffects' calling private method 'startSpawnEffect' with arguments 'newUnit.currentTile' and 'spawn'
ReflectionUtility.Reflection.CallMethod(MapBox.instance.stackEffects, "startSpawnEffect", newUnit.currentTile, "spawn");
//...
using ReflectionUtility;
//...
//Checking if '(Kingdom)kingdom' is enemy for '(Kingdom)pActor.kingdom' calling private method 'isEnemy' with argument '(Kingdom)kingdom', receiving 'bool'
var isEnemy = (bool)pActor.kingdom.CallMethod("isEnemy", kingdom);
//...

# CallStaticMethod(type, methodName, params args): object

Call static private method

Parameter Type Optional Description
type Type No Type of object from which you want to call static method
methodName string No Method name
args params object[] No Method arguments

Returns: object

Examples:

using ReflectionUtility;
//...
//Checking for existance window with id 'inspect_unit'
Reflection.CallStaticMethod(typeof(ScrollWindow), "checkWindowExist", "inspect_unit");
//...

# GetField(type, instance, fieldName): object

Get value from private field

Parameter Type Optional Description
type Type No Type of object from which you want to get field
instance object No Instance of type
fieldName string No Name of field from which you want to receive value

Returns: object

Examples:

using ReflectionUtility;
//...
//Get private field '(Dictionary<string, string>)localizedText' from 'LocalizedTextManager' which contains translations texts
var texts = (Dictionary<string, string>)Reflection.GetField(LocalizedTextManager.instance.GetType(), LocalizedTextManager.instance, "localizedText");
//...
using ReflectionUtility;
//...
//Get static private field '(Dictionary<string, ScrollWindow>)allWindows' from 'ScrollWindow' which contains all ScrollWindow windows
Reflection.GetField(typeof(ScrollWindow), null, "allWindows") as Dictionary<string, ScrollWindow>;
//...

# SetField(originalObject, fieldName, T newValue): void

Set value to private field

Parameter Type Optional Description
originalObject object No Object in which you want to change field value
fieldName string No Field name
newValue generic type No New field value

Returns: void

Examples:

using ReflectionUtility;
//...
//Set value '(Race)raceObj' to 'race' field in '(City)city' object
Reflection.SetField<Race>(city, "race", raceObj);
//...