jjzjj

StackFrame

全部标签

c# - 获取特定的 StackFrame 而不是 StackTrace.GetFrame 是否更便宜?

如果我只是想执行以下操作以查看是什么调用了我,varst=newStackTrace();varcallingMethod=st.GetFrame(1).GetMethod()只购买那个特定的框架会更便宜吗?varsf=newStackFrame(1);varcallingMethod=sf.GetMethod()我用下面的代码进行了测试,但我不确定我的方法是否合理。Stopwatchsw=Stopwatch.StartNew();for(inti=0;i我的方法(和结果)是否正确?编辑我会使用CallerInformation属性,但是,我暂时停留在.NET3.5中。

c# - StackFrame 在 Release模式下表现不同

这是我的代码:publicclassUserPreferences{//////TheEMailsignature.///[UserPreferenceProperty(Category="Email",DefaultValue="Mydefaultvalue")]publicstaticstringSignature{get{returnUserPreferenceManager.GetValue();}set{UserPreferenceManager.SetValue(value);}}}publicstaticstringGetValue(){if(((VTXPrincipal

c# - 如何通过反射获取当前属性名称?

当我在其中时,我想通过反射获取属性名称。可能吗?我有这样的代码:publicCarTypeCar{get{return(Wheel)this["Wheel"];}set{this["Wheel"]=value;}}因为我需要更多这样的属性,所以我想做这样的事情:publicCarTypeCar{get{return(Wheel)this[GetThisPropertyName()];}set{this[GetThisPropertyName()]=value;}} 最佳答案 由于属性实际上只是方法,您可以执行此操作并清理返回的get

c# - 如何通过反射获取当前属性名称?

当我在其中时,我想通过反射获取属性名称。可能吗?我有这样的代码:publicCarTypeCar{get{return(Wheel)this["Wheel"];}set{this["Wheel"]=value;}}因为我需要更多这样的属性,所以我想做这样的事情:publicCarTypeCar{get{return(Wheel)this[GetThisPropertyName()];}set{this[GetThisPropertyName()]=value;}} 最佳答案 由于属性实际上只是方法,您可以执行此操作并清理返回的get

c# - StackFrame 的性能如何?

我正在考虑使用类似StackFramestackFrame=newStackFrame(1)的东西来记录执行方法,但我不知道它对性能的影响。堆栈跟踪是在每次方法调用时构建的东西,所以性能不应该是一个问题,还是它只是在被要求时构建的东西?您是否建议在性能非常重要的应用程序中反对它?如果是这样,是否意味着我应该在发布时禁用它? 最佳答案 编辑:一些背景我们有一个类似的功能,但99%的时间都被禁用;我们使用的方法如下:publicvoidDoSomething(){TraceCall(MethodBase.GetCurrentMethod