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. php第五节(字符串函数和时间、日期函数)

    <?php //查找字符串函数 // strpos() 查找字符第一次出现的位置 重点区分大小写 //stripos — 查找字符串首次出现的位置(不区分大小写) //strrpos — 计算指 ...

  2. 增删改查 报异常org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readO

    可能是Spring配置文件 事务通知里面的方法  与实际方法不匹配 <tx:advice id="advice" transaction-manager="tran ...

  3. mongodb的高级查询

    db的帮助文档 输入:db.help(); db.AddUser(username,password[, readOnly=false])  添加用户 db.auth(usrename,passwor ...

  4. Delphi方法

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

  5. CentOS下禁止防火墙

    CentOS下禁止防火墙 1.使用如下命令安装iptables-services. yum install -y iptables-services 2.关闭防火墙. service iptables ...

  6. 10---git安装

    卸载原来的版本: # 查看版本 git --version # 移除原来的版本 yum remove git 安装依赖库: yum install curl-devel expat-devel get ...

  7. Python3乘法口诀表(由上至下+由下至上)

    一.所用知识点: 1.变量的使用. 2.循环语句的使用,这里用到的是双while循环.当然,使用其他的循环去做也是可以的.我认为,对于刚刚接触编程的人来说,使用双while循环比较容易理解. 3.使用 ...

  8. python中矢量化字符串方法

  9. octave简易操作

    语言以分号;结尾if for while等语句后用,来承接关系if ,elseif ,else ,end;for i=1:10,end;while a>3 ,end;   while true, ...

  10. ChipScope软件使用

    内容组织 1.建立工程  2.插入及配置核  2.1运行Synthesize  2.2新建cdc文件  2.3 ILA核的配置  3. Implement and generate programmi ...