using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; class test { { Console.WriteLine("1:__" + "Method调用成功!"); } { Console.WriteLine("2:__" + str); } { string classNam
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace stringConvertClass { class test { public void Method() { Console.WriteLine("调用成功!"); } public void Method
在写记录日志功能时,需要记录日志调用方所在的模块名.命名空间名.类名以及方法名,想到使用的是反射(涉及到反射请注意性能),但具体是哪一块儿还不了解,于是搜索,整理如下: 需要添加相应的命名空间: using System; using System.Diagnostics; using System.Reflection; 如果仅是获取当前方法名使用 MethodBase.GetCurrentMethod 方法(返回表示当前正在执行的方法的 MethodBase 对象),可以使用如下代码: pu
一.获取 命名空间 类名 方法名 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Reflection; namespace GetMethodNameSpace { class Program { public static string GetMethodInfo() { string str
平时我们在记录日志的时候难免会需要直接记录当前方法的路径,以便查找,但是每次都输入方法名称非常的繁琐,同时如果修改了方法名称也要去手动修改日志内容,真的是劳命伤财啊,所以有了如下方法则可解决我们的大难题啊,闲话少说,直接上代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Reflecti