프로그래밍 노트

C# 이전 함수명, 이전 클래스명 알아내기 본문

카테고리 없음

C# 이전 함수명, 이전 클래스명 알아내기

떡잎 2014. 11. 7. 18:30



using System;

using System.Diagnostics;


namespace GetFunctionName

{

    public static class cs

    {

        public static string  test(object sender)

        {

            // 이전 함수명 

            string prevFuncName = new StackFrame(1, true).GetMethod().Name;

            // 이전 Class명

            string prevClassName = new StackTrace().GetFrame(1).GetMethod().ReflectedType.Name;

            return prevFuncName + " - " + prevClassName; ;

        }

    }

}


c#에서는 자신을 부른 함수명이 무엇인지

그리고 그 함구가 어떤 Class였는지를 쉽게 알 수 있다.

Log 출력할 때 도움이 될 것 같다.

Comments