[Reflection] Invoking method passed by string

Today I got an idea to do some basic data manipulation through a terminal, and since I’m a bit lazy I wanted to be able to type something like Substring to preform a substring for a string. I was thinking that it should be possible with┬áreflection and sure, I was right ­čÖé

The only problem I had was that I needed to pass what parameters the method takes and┬áparse that parameter. It’s ugly, but for a test it worked. The reson for this is that substring is overloaded. Both (int startIndex) and (int startIndex, int┬álength);

Below is the ugly code from my first test.

Since I will only use this for my own classes which has no overloading I don’t have to specify the parameters.┬áThe casting will also be avoided if i just do pass string all over and cast later. So, all in all, this will be helpful ­čÖé

Leave a Reply

Your email address will not be published. Required fields are marked *