现在的位置: 首页 > 综合 > 正文

HOW TO:获取执行代码所处环境信息(小结)

2011年05月03日 ⁄ 综合 ⁄ 共 547字 ⁄ 字号 评论关闭

一般是静态方法

一、程序域

System.AppDomain.CurrentDomain

二、程序集

程序入口
System.Reflection.Assembly.GetEntryAssembly()

当前方法所在
System.Reflection.Assembly.GetExecutingAssembly()

当前方法的调用者方法所在
System.Reflection.Assembly.GetCallingAssembly()

三、当前方法
System.Reflection.MethodBase.GetCurrentMethod()

还可以从实例中找
Dim mStackFrame As New System.Diagnostics.StackFrame
mStackFrame.GetMethod()

Dim mStackTrace As New System.Diagnostics.StackTrace
For Each mStackFrame As System.Diagnostics.StackFrame In mStackTrace.GetFrames
    mStackFrame.GetMethod()
Next

四、其它,当前进程
System.Diagnostics.Process.GetCurrentProcess()

抱歉!评论已关闭.