#Reflection

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

#Constructors

No constructors


#Fields

No fields


#Methods

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

Call private method

ParameterTypeOptionalDescription
othis objectNoOjbect, from which you want to call method
methodNamestringNoMethod name
argsparams object[]NoMethod 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

ParameterTypeOptionalDescription
typeTypeNoType of object from which you want to call static method
methodNamestringNoMethod name
argsparams object[]NoMethod 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

ParameterTypeOptionalDescription
typeTypeNoType of object from which you want to get field
instanceobjectNoInstance of type
fieldNamestringNoName 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

ParameterTypeOptionalDescription
originalObjectobjectNoObject in which you want to change field value
fieldNamestringNoField name
newValuegeneric typeNoNew field value

Returns: void

Examples:

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