一、获取 命名空间 类名 方法名

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().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();
}
}
}

二、利用反射动态加载dll

头部引用加:

using System.Reflection;
Assembly asm = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory+ "/DeclareDLL/YunDouTaxLib.dll");////我们要调用的dll文件路径
//加载dll后,需要使用dll中某类.
Type t = asm.GetType("namespace.classname");//获取类名,必须 命名空间+类名 //实例化类型
object o = Activator.CreateInstance(t); //得到要调用的某类型的方法
MethodInfo method = t.GetMethod("functionname");//functionname:方法名字 object[] obj =
{
Parameters[].TaxpayerName,
Parameters[].TaxpayerTaxCode,
Parameters[].CAPassword
};
//对方法进行调用
var keyData = method.Invoke(o, obj);//param为方法参数object数组

三,没有Assembly.LoadFrom 需要在程序中加引用

C# 反射总结 获取 命名空间 类名 方法名的更多相关文章

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

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

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

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

  3. C# 获取方法所在的 命名空间 类名 方法名

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

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

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

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

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

  6. ThinkPHP 3.2 中获取所有函数方法名,以及注释,完整可运行

    <?php namespace Home\Controller; use Common\Controller\BaseController; class AuthController exten ...

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

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

  8. [No000085]C#反射Demo,通过类名(String)创建类实例,通过方法名(String)调用方法

    using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...

  9. PHP获取当前类名、函数名、方法名

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

随机推荐

  1. [CF920G]List Of Integers

    Description: \(t\)组询问,求第\(k\)个大于\(x\)且与\(p\)互质的数 Hint: \(x,k,p<=1e6,t<=30000\) Solution: 推出式子后 ...

  2. 20172302 《Java软件结构与数据结构》第三周学习总结

    2018年学习总结博客总目录:第一周 第二周 第三周 教材学习内容总结 第五章 队列 1.队列是一种线性集合,其元素从一端加入,从另一端删除:队列元素是按先进先出(FIFO(First in Firs ...

  3. dataGridView使用指南系列一、回车换行或换列完美解决方案

    在使用datagridview控件时,默认按回车是跳转到下一行的当前列的,要想让按回车跳转到同一行的下一列该怎么做呢? 百度搜索了一下,大都是使用该控件的key_down事件和CellEndEdit进 ...

  4. Map和String类型之间的转换

    前提是String的格式是map或json类型的 public static void main(String[] args) { Map<String,Object> map = new ...

  5. 1.2 Stream API

    引例: List<String> strList = Arrays.asList("zhaojigang","nana","tianya& ...

  6. Spark2.2(三十八):Spark Structured Streaming2.4之前版本使用agg和dropduplication消耗内存比较多的问题(Memory issue with spark structured streaming)调研

    在spark中<Memory usage of state in Spark Structured Streaming>讲解Spark内存分配情况,以及提到了HDFSBackedState ...

  7. [Java] LinkedHashMap 源码简要分析

    特点 * 各个元素不仅仅按照HashMap的结构存储,而且每个元素包含了before/after指针,通过一个头元素header,形成一个双向循环链表.使用循环链表,保存了元素插入的顺序. * 可设置 ...

  8. Visual Studio 打开程序提示仅我的代码怎么办

    工具-->选项--->调试---->常规-->禁用"启动仅我的代码"

  9. efcore数据库自动生成

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. p ...

  10. LeetCode Permutations问题详解

    题目一 permutations 题目描述 Given a collection of numbers, return all possible permutations. For example,[ ...