Skip to main content
gamedev.net
🔒 Locked

String to MethodName

Started by Kalthorn Jul 28, 2006 at 7:28 PM 2 replies 800+ views
Original Post
Kalthorn
Kalthorn
Is it possible (in C#) to convert a string into all or part of a method or variable type? I want to avoid having a Collection of string keys matched to delegate values. Instead of (Key, Value) for ("Move", OnMoveEvent) I want to just build a delegate based on a string parameter ala: OnEvent where the final string actually matches a predefined method (OnMoveEvent() already exists). Along these same lines is it possible to convert strings to reference types of any other kind, such as a class? I am aware of stuff like atoi() but what is the way to essentially get atoEnum() or atoClass()? Thank in advance for any replies.
SiCrane
SiCrane
You might want to check out the System.Reflection namespace.
Kalthorn
Kalthorn
So I get a list of the Class methods, drop a ToString() on each one and compare that against the given string?
nife
nife
Quote:
Original post by Kalthorn
So I get a list of the Class methods, drop a ToString() on each one and compare that against the given string?


You might want to create a hashmap (or a similar hashing container in C#) of those strings to speed up the process a bit.
Killers don't end up in jailThey end up on a high-score!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.