View Single Post
Old 10-26-2004, 09:51 PM   #4
Yui Unifex
Senior Member
 
Join Date: Apr 2002
Location: Florida
Posts: 323
Yui Unifex is on a distinguished road
Send a message via ICQ to Yui Unifex Send a message via AIM to Yui Unifex
Question

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.
Yui Unifex is offline   Reply With Quote