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 = "";
//取得当前方法命名空间
str += "命名空间名:" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "\n";
//取得当前方法类全名
str += "类名:" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName + "\n";
//取得当前方法名
str += "方法名:" + System.Reflection.MethodBase.GetCurrentMethod().Name + "\n";
str += "\n"; StackTrace ss = new StackTrace(true);
MethodBase mb = ss.GetFrame(1).GetMethod();
//取得父方法命名空间
str += mb.DeclaringType.Namespace + "\n";
//取得父方法类名
str += mb.DeclaringType.Name + "\n";
//取得父方法类全名
str += mb.DeclaringType.FullName + "\n";
//取得父方法名
str += mb.Name + "\n";
return str;
} public static void Main()
{
Console.WriteLine(GetMethodInfo()); Console.ReadKey();
}
}
}

C# 获取方法所在的 命名空间 类名 方法名的更多相关文章

  1. c# 获取方法所在的命名空间 类名 方法名

    平时我们在记录日志的时候难免会需要直接记录当前方法的路径,以便查找,但是每次都输入方法名称非常的繁琐,同时如果修改了方法名称也要去手动修改日志内容,真的是劳命伤财啊,所以有了如下方法则可解决我们的大难 ...

  2. C# 反射总结 获取 命名空间 类名 方法名

    一.获取 命名空间 类名 方法名 using System; using System.Collections.Generic; using System.Linq; using System.Tex ...

  3. c# 获取命名空间 类名 方法名

    c# 获取命名空间 类名 方法名 转[http://blog.sina.com.cn/s/blog_3fc2dcc1010189th.html]   分类: Winform public static ...

  4. Java获取当前运行方法所在的类和方法名

    很简单,直接看代码: public void showClassAndMethod() { System.out.println(this.getClass().getSimpleName() + & ...

  5. java反射查看jar包中所有的类名方法名

    不反编译,不用其他工具,用java反射查看jar包中所有的类名方法名,网上很多都报错,下面这个你试试看:话不多说直接撸代码: import java.lang.reflect.Field; impor ...

  6. C#基础-获得当前程序的 空间名.类名.方法名

    string typeName = this.GetType().ToString();//空间名.类名 string typeName = this.GetType().Name;//类名 new ...

  7. Java中获取运行代码的类名、方法名

    以下是案例,已运行通过 package com.hdys; /* * 1.获取当前运行代码的类名,方法名,主要是通过java.lang.StackTraceElement类 * * 2. * [1]获 ...

  8. .NET 中获取调用方法名

    在写记录日志功能时,需要记录日志调用方所在的模块名.命名空间名.类名以及方法名,想到使用的是反射(涉及到反射请注意性能),但具体是哪一块儿还不了解,于是搜索,整理如下: 需要添加相应的命名空间: us ...

  9. PHP 获取当前所在的类名、方法名等

    PHP获取当前类名.方法名  __CLASS__ 获取当前类名  __FUNCTION__ 当前函数名(confirm)  __METHOD__ 当前方法名 (bankcard::confirm) _ ...

随机推荐

  1. Spring的声明式事务----Annotation注解方式(1)

    这里列一个小的demo工程,直接利用Spring的jdbcTemplate访问Mysql数据库. 工程结构: 数据库中的tbl_student表结构如下: 数据实体类Student.java代码如下: ...

  2. lua浮点数取整

    向下取整 math.floor(num) 向上取整 math.ceil(num) 取整取余 math.modf(num) 测试 num = 12.4 print(math.floor(num)) 12 ...

  3. chromium之tracked

    //------------------------------------------------------------------------------ // Tracked is the b ...

  4. linux命令系列-ln(软硬链接)

    linux命令 ln命令可以生成软链接和硬链接,也可叫做符号链接和实体链接. 有兴趣深入理解的可以查阅相关文档,一般的读者只需记住以下几点即可: .不管是软链接还是硬链接都不会额外增加磁盘空间(虽然实 ...

  5. Linux给当前用户指定目录授权命令

    使用命令: chown -R user:user ./local 说明:user 为当前用户: 完毕!

  6. centos7-mongodb3.4.6集群的搭建

    0.需要环境 安装包:mongodb-linux-x86_64-3.4.6.tgz 安装路径:/usr/mongodb 服务器: 192.168.177.131/132/133 mongos 2000 ...

  7. [转]select top n 动态赋值

    怎样实现 select top n 语句中 n 的动态赋值呢?怎样实现 select   top   n   语句中 n 的动态赋值,求教各位了. 要把这个n值传到存储过程中,再加入 select t ...

  8. php-语言参考-类型3.2-未完待续

    一,PHP变量的8个类型 四种标量类型: boolean (布尔型) integer (整型) float (浮点型, 也称作 double) string (字符串) 两种复合类型: array ( ...

  9. Delphi 过程类型

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  10. MongoDB修改数据库名,collection名

    利用dropDatabase,copyDatabase修改Database名称 db.copyDatabase('old_name', 'new_name'); use old_name db.dro ...