Can reflection be used to bind one function to another without the use of delegates?
class A
{
void Foo()
{
}
}
class B
{
void Main()
{
A a = new A();
a.GetType().GetMethod("Foo").AddHook(a, Func);
a.Foo();
}
void Func()
{
}
}
Is there a way to call Func
after a call Foo
without using events, delegates, or just calling Func
from inside Foo
?
I need this so that my game user interface can update.
As I can see, most people come across this by adding a bunch of events to and subscribing B to them. Like this
class A
{
public delegate void UICallback();
public event UICallback onFoo;
void Foo()
{
onFoo.Invoke();
}
}
class B
{
void Main()
{
A a = new A();
a.onFoo += Func;
a.Foo();
}
void Func()
{
}
}
, , , , (, 5 10), , , UI (, invoke onBattleStarted StartBattle()). , , , .
, , ... , Func
Foo
- Foo
, .. Foo
, , . , Foo
, Func
!