Call function on an object that is not defined?

I want something like this:

public GameObject go;
public Type functionType;

void Start() {
    go.GetComponent<functionType>().GetMethod(someMethod, BindingFlags.Default).Invoke(this, new Object[0]);
}

For the most part it works, but if I replace it with typeof(SomeType).GetMethod.
What can I do to call a method this way?

That line makes no sense at all. Inside generic brackets you can only use actual types, not System.Type object references. Those belong to the reflection system. A System.Type object is not a compile time type reference, it’s an object that describes a certain type at runtime.

Example:

System.Type tmp = typeof(MyType);

Here “MyType” is an actual compile time type reference. Those can be used as generic parameters. the “typeof” operator returns the System.Type object for the given type. As mentioned, you can’t use variables or objects as generic parameters.

Next thing is i’m not sure what kind of type object you actually store inside your “functionType” variable. Methods don’t have some kind of “function type”. Methods are described by a MethodInfo instance which is returned by GetMethod of a System.Type object.

If you want to dynamically get a component of “functionType” and call a method with the name “someMethod” you might want to do this:

Component inst = go.GetComponent(functionType);
if (inst != null)
{
    System.Type type = inst.GetType(); // get the actual type in case it's a derived type. otherwise just use "functionType".
    MethodInfo method = type.GetMethod(someMethod,BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
    method.Invoke(inst, null);
}

With those bindingflags it would search for an instance method (not static) that is either public or private. The Invoke method of the MethodInfo object takes two parameters. The first one is the reference to the actual object where you want to call that method on. The object you pass here has to be of the type where this MethodInfo object was returned from. If you use GetType (as i did in my example) you can be sure that if you actually find a method with GetMethod that you can call it on that object. Static methods don’t require an object, so the first parameter has to be null in that case.

The second parameter is an array with the parameters for the method. In case of no parameters you should just pass “null”.