Not only is it possible with C#, it's much, much easier because you can use either delegates or reflection to get at what you need. I would suggest reflection since you can't retarget (change the 'this' target) of a non-static delegate, and static delegates always have a null 'this' target. It's a terrible limitation I know, but they don't have me designing these languages so I'm content to merely complain about them on mud forums...
The reflection method is very easy. Say you've got an object called 'Player' which can execute the 'CmdLook' method when the player types 'look'
[code] using System.Reflection;
...
Type playerType = typeof(Player);
MethodInfo lookMethod = playerType.GetMethod("CmdLook");[/quote]
Now say you want to invoke the method with a played named 'actor' as 'this', a target player named 'target', and a string of miscellaneous text named 'args':
[code] lookMethod.Invoke(actor, new object[] {target, args});[/quote]
Which will jump into code like this on the Player object:
[code] class Player...
public void CmdLook (Player target, string args) {
...
}[/quote]
It's extremely simple. Look into the System.Type.GetMethod method.
|