RT...
比如说SqlHelper提供的一些公共静态方法,我在其他地方写下如下代码:public class A
{
public A()
{
DataSet ds = SqlHelper.ExecuteDataset(...);
}
}我怎么做才能在SqlHelper的ExecuteDataset方法中取得类A的名字?
谢谢大家了...
PS.随着公司开发任务的减少,来这里的次数少多了...而且,好友们的热度也都是0...唉

解决方案 »

  1.   

    传入
    public class A
    {
        public A()
        {
            DataSet ds = SqlHelper.ExecuteDataset("A",...);
        }
    }
      

  2.   

        StackTrace stackTrace = new StackTrace();
        StackFrame stackFrame = stackTrace.GetFrame(1);
        MethodBase methodBase = stackFrame.GetMethod();    Console.WriteLine( " Method Name {0} ", methodBase.Name ); 
      

  3.   

    参考:        static void Main(string[] args)
            {
                A.AMethod();
            }        class A
            {
                public static void AMethod()
                {
                    StackTrace st = new StackTrace();
                    for (int i = 0; i < st.FrameCount; i++)
                    {
                        if (st.GetFrame(i).GetMethod() == MethodBase.GetCurrentMethod() && i != st.FrameCount - 1)
                        {
                            Console.WriteLine("当前调用该方法的方法名为:{0}", st.GetFrame(i + 1).GetMethod().Name);
                            break;
                        }
                    }
                }
            }
      

  4.   

    呃...传入,是可以啦...但是这是要增加方法的一个参数啊...既存代码可修改不起啊...StackTrace 能详细说明一下吗?
      

  5.   

    呵呵,看错了,改一下:                        Console.WriteLine("当前调用该方法的类名为:{0}", st.GetFrame(i + 1).GetMethod().ReflectedType.Name);