Edit: In real life i don’t have a Book class. This is just an example to be clear. Real problem really needs reflection to solve it.
Suppose that I have some classes:
Book, Apple, Door.
class Book
{
...
public decimal getPrice()
{...}
public string getTitle()
{...}
public decimal getAuthor()
{...}
}
and something same for other classes.
May i call a class method dynamically from a string:
Book myBook = new Book("Title", "Author", 44);
string title = runMethod(myBook, "getTitle");
You can use something like this, using reflection: