代码之家  ›  专栏  ›  技术社区  ›  Exitos

如何在静态方法中使用反射

  •  1
  • Exitos  · 技术社区  · 15 年前

    我有一种测井方法:

        public static void WriteSimpleDebugTrace(string logFilePathArg, string messageArg)
        {
    
            StreamWriter writer;
    
            //Environment.ExpandEnvironmentVariables("%SystemDrive%") [will get to the c drive]
            if (EnumsAndConstants.EnableApplicationLogging)
            {
                writer = new StreamWriter(logFilePathArg, true);
                writer.Write("Time: " + DateTime.Now.ToString() + " Message: " + messageArg);
                writer.Write(Environment.NewLine);
                writer.Flush();
                writer.Close();
            }
    
        }
    

    我正试图访问这个.getType().name,但我不允许访问它。这附近还有吗?当调用此方法时,我希望轻松获取调用类名,而不必重写对此方法的所有调用…

    2 回复  |  直到 15 年前
        2
  •  0
  •   vc 74    15 年前

    stackTrace.GetFrame(1).GetMethod()

    推荐文章