- Home /
Parse String to select certain variable
I am working on a inspector tool. I am wondering how can I pick/affect a variable in a object using a string (written variable name).
Example:
public class Data {
public int score;
}
public class Check {
public Data data;
public void Something() {
Affect( data, "score", 10 );
}
public void Affect( Object obj, string variableName, ... ){
//No idea what I should do
}
}
I am not exactly sure what I should search in Google at all. It will be greatly if someone can point me to the right direction/articles/webpage.
Comment
Best Answer
Answer by MikeNewall · Apr 17, 2014 at 04:42 PM
You can do that in c# using reflection.
Take a look at this.
http://msdn.microsoft.com/en-us/library/6z33zd7h(v=vs.110).aspx
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Getting variables by their names? 3 Answers
Distribute terrain in zones 3 Answers
Variable References in C# from JS 1 Answer
Assigning current color to a variable for fade out (C#) 0 Answers