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. B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛

    You are given a list of train stations, say from the station 1 to the station 100. The passengers ca ...

  2. android Volley+Gson的使用

    听说Volley框架非常好用,今天试了一下post请求,果然如此,因为我传的是json获取的也是json所以就写了一种关于json的请求,其实其他的代码都差不多.首先要先创建一个全局的变量,请求入队列 ...

  3. 【shell脚本学习-2】

    #!/bin/bash - #echo do you have exetuate this project \n printf "please input your passwd" ...

  4. JDK7 新特性

    JDK7新特性的目录导航: 二进制字面值 switch 语句支持 String try-with-resources catch 多个类型异常 字面值中使用下划线 类型推断 改进泛型类型可变参数 其它 ...

  5. js实现监听浏览器窗口大小改变事件

    window.onresize = function(){   }

  6. ruby 比较符号==, ===, eql?, equal?

    “==” 最常见的相等性判断 “==” 使用最频繁,它通常用于对象的值相等性(语义相等)判断,在 Object 的方法定义中,“==” 比较两个对象的 object_id 是否一致,通常子类都会重写覆 ...

  7. 杭电 1003 Max Sum (动态规划)

    参考:https://www.cnblogs.com/yexiaozi/p/5749338.html #include <iostream> #include <cstdio> ...

  8. ABAP CDS ON HANA-(10)項目結合して一つ項目として表示

    Numeric Functions ABS(arg)  CEIL(arg) DIV(arg1, arg2) DIVISION(arg1, arg2, dec) FLOOR(arg) MOD(arg1, ...

  9. P1196 银河英雄传说(加权并查集)

    P1196 银河英雄传说 题目描述 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦 创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在 ...

  10. 3468-A Simple Problem with Integers 线段树(区间增减,区间求和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 110077 ...