C#: how to get an object by the name stored in String?

后端 未结 4 1781
南方客
南方客 2020-12-06 21:44

is it possible in C# to get an object by name?

i.e. get this.obj0 using

string objectName = \"obj0\";
executeSomeFunctionOnObject(this.someLoadObject         


        
4条回答
  •  天涯浪人
    2020-12-06 22:07

    Well I think what you are looking for is Reflection.

    You can see a good example here: http://www.switchonthecode.com/tutorials/csharp-tutorial-using-reflection-to-get-object-information

    As said before - objects don't have names but you can traverse the objects and get their type and act accordingly.

    This blog here shows a real good example of traversing and usage of reflection.

    This should be a good start for sure. Enjoy!

提交回复
热议问题