日期:2014-05-17 浏览次数:20806 次
public static void getFileName()
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(1);
MethodBase method = frame.GetMethod();
String className = method.ReflectedType.Name;
Console.Write("ClassName:" + className + "\nMethodName:" + method.Name);
System.Diagnostics.Debug.WriteLine("ClassName:" + className + "\nMethodName:" + method.Name+"\n命名空间:"+ method.ReflectedType.Namespace);
}
private A(){}
public static A GetA)
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(1);
MethodBase method = frame.GetMethod();
String className = method.ReflectedType.Name;
if (className.Equals("X"))
{
return new A();
}
return null;
}