c# execute a string as code

后端 未结 6 1728
难免孤独
难免孤独 2020-12-10 18:44

Here is what i want to do, and i know it is possible with perl, php, python and java, but i am working with c#

how can i do the following:

public voi         


        
6条回答
  •  误落风尘
    2020-12-10 19:25

    Are you saying that AVeryLargeWebServiceWithLotsOfMethodsToCall is an instance of an object on which you want to invoke a method named functionName? If so:

    MethodInfo method = AVeryLargeWebServiceWithLotsOfMethodsToCall.GetType().GetMethod(functionName);
    method.Invoke(AVeryLargerWebServiceWithLotsOfMethodsToCall, null);
    

    Or is AVeryLargeWebServiceWithLotsOfMethodsToCall a type on which you want to invoke a static method named functionName? If so:

    MethodInfo method = typeof(AVeryLargeWebServiceWithLotsOfMethodsToCall).GetMethod(functionName);
    method.Invoke(null, null);
    

提交回复
热议问题