2013-03-13 4 views
0

방법 :는 단위 테스트에서 작동하지 않습니다

private static HipKvp[] GetRequestParameterArray(CaptchaRequestModel request){} 

단위 테스트 :

HipKvp[] input = (HipKvp[])privObj.Invoke("GetRequestParameterArray", new CaptchaRequestModel[] { result }); 

예외 :

MissingMethodException was unhandled by user code: 
Attempted to access a missing member. 

다른 방법을 시도했지만 작동하지 않았습니다.

+0

알고 [작동하는 (http://stackoverflow.com/questions/8609595/using-privateobject-invoke-to -call-a-static-conversion-function-do-not-compile-i). 철자 및 객체 유형을 확인하십시오. –

+0

http://tackoverflow.com/questions/5396996/how-can-i-use-privateobject-to-access-private-members-of-both-my-class-and-its-p 링크 - 바인딩 플래그를 전달하십시오. –

답변

0

PrivateObject.Invoke(String, Object[])은 구성원이 반드시 인 것은 아니지만 개체에이 속하기 때문에 정적 구성원을 만지지 않습니다.

은 당신과 같이 두 번째 매개 변수에 BindingFlags.NonPublic | BindingFlags.StaticPrivateObject.Invoke(String, BindingFlags, Object[])를 사용하여 지정해야합니다

HipKvp[] input = (HipKvp[])privObj.Invoke("GetRequestParameterArray", BindingFlags.NonPublic | BindingFlags.Static, new CaptchaRequestModel[] { result }); 
관련 문제