2011-03-30 6 views
3

현재 응용 프로그램에 대한 오류 로거를 작성하고 있으며 기본적으로 내가 관심있는 것은 예외를 처리 할 때 함수를 호출 할 때입니다. CreateLogEntry (...)에서 내 로깅 클래스. 아이디어가 있습니다, 나는 CreateLogEntry (...)이 메소드 BadFunction (...)에서 호출되었으며 로깅 프로세스의 일부로 해당 매개 변수를 검색한다는 것을 알고 싶습니다.C에서 호출 메서드 속성을 얻는 방법 #

이제 숙제를했다. (충분하지는 않지만 : S), 내 솔루션은 System.Reflection에 있으며 이미 클래스 내의 모든 함수를 열거하는 방법에 대한 예제를 발견했다. http://www.csharp-examples.net/get-method-names/). 하지만 예외를 생성하는 함수의 이름을 가져 오는 것이 가능할 것입니다.

예는 (내가 가진 무엇) :

내가 가지고 싶은
public string GetCurrentMode() 
    { 
     string currentMode = ""; 

     try 
     { 
      currentMode = _host.Mode.ToString(); 
     } 
     catch(Exception ex) 
     { 
      Common.MorpheeException me = new Common.MorpheeException(); 

      me.MethodName = "GetCurrentMode"; 
      me.NameSpace = "MorpheeScript"; 
      me.ErrorNumber = 0; 
      me.ErrorDescription = ex.Message; 
      me.StackTrace = ex.StackTrace; 

      throw new FaultException<Common.MorpheeException>(me); 
     } 

     return currentMode; 
    } 

: 당신의 도움이

+0

가능한 [C#의 리플렉션 : 호출하는 메서드 이름과 형식을 가져 오는 방법은 무엇입니까?] (http://stackoverflow.com/questions/3095696/reflection-in-c-how-do-i-get- 호출 방법 이름 및 유형) – Oliver

답변

0

신경 끄시에 대한

 public string GetCurrentMode() 
    { 
     string currentMode = ""; 

     try 
     { 
      currentMode = _host.Mode.ToString(); 
     } 
     catch(Exception ex) 
     { 
      Common.MorpheeException me = new Common.MorpheeException(ex); 

      // Here me should know that it is called from GetCurrentMode() and 
      // retrieve the parameters if there are any 
      throw new FaultException<Common.MorpheeException>(me); 
     } 

     return currentMode; 
    } 

많은 감사합니다, 나는 How do I get the calling method name and type using reflection?

에 내 대답을 발견
관련 문제