Jump to content
  • Advertisement
Sign in to follow this  
Kalthorn

String to MethodName

This topic is 4316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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: On<InsertedString>Event 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.

Share this post


Link to post
Share on other sites
Advertisement
So I get a list of the Class methods, drop a ToString() on each one and compare that against the given string?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!