2012-01-25 30 views
0

我試圖通過querysting,要調用的方法名稱,並有ProcessRequest在我的處理程序中調用該方法。我在這裏學習,所以最好的辦法是做什麼。這是我有...傳遞方法名稱以調用處理程序

我得到了methodInfo.Invoke上的錯誤The best overloaded method match for Invoke(object, object[]) has some invalid arguments

public class SocialSharingHandler : IHttpHandler 
{ 

    public void ProcessRequest(HttpContext context) 
    { 
     string method = (string)context.Request.QueryString["m"]; 
     if (!string.IsNullOrEmpty(method)) 
     { 
      MethodInfo methodInfo = typeof(SocialSharingHandler).GetMethod(method); 
      methodInfo.Invoke(new SocialSharingHandler(), context.Request.Form); 
     } 
    } 
.... 

回答

1
methodInfo.Invoke(new SocialSharingHandler(), new object[] { context.Request.Form }); 
+0

感謝你,似乎解決這個問題,它會編譯,但我不是在一個點看看是否運行。謝謝vc! – bflemi3

+0

@ bflemi3不客氣:) –

0

錯誤消息指出預計帕拉姆類型的對象和目標對象的數組[]

public class SocialSharingHandler : IHttpHandler 
{ 
    public void ProcessRequest(HttpContext context) 
    { 
     string method = (string)context.Request.QueryString["m"]; 
     if (!string.IsNullOrEmpty(method)) 
     { 
       MethodInfo methodInfo = typeof(SocialSharingHandler).GetMethod(method); 
       methodInfo.Invoke(new SocialSharingHandler(), new object[] { context.Request.Form }); 
     }  
    } 
} 
相關問題