反射_程序集_额外补充
来源:互联网 发布:mongodb删除数据 编辑:程序博客网 时间:2024/05/18 15:08
反射_程序集_额外补充<18/9/2017>
using System;using System.Collections.Generic;using System.Linq;using System.Reflection;//反射需要引用命名空间using System.Text;using System.Threading.Tasks;namespace 反射{ class Program { static void Main(string[] args) { Type t = Type.GetType("反射.Animal"); Type t1 = typeof(Animal); Console.WriteLine(t.Equals(t1));//返回为true,返回对象是一样的 ConstructorInfo info = t.GetConstructor(new Type[] { typeof(int), typeof(string) }); object o = info.Invoke(new object[] { 1, "abc" }); //上面两句代码等同于下面这行代码 object o1 = Activator.CreateInstance(t, new object[] { 1, "adc" }); // MethodInfo mi = t.GetMethod("Run"); mi.Invoke(o1, null); MethodInfo mm = t.GetMethod("Sing"); mm.Invoke(null, null); //1.静态方法可以传空执行,非静态方法必须有一个目标对象,如上 //2.可以返回一个结果,如下 MethodInfo mm1 = t.GetMethod("Sing2"); object sss = mm1.Invoke(null,null); Console.WriteLine(sss); PropertyInfo[] pies= t.GetProperties(); pies[0].SetValue(o1, 1001); Console.WriteLine(((Animal)o1).Id); } } public class Animal { public int Id { get; set; } public int a; public string b; public Animal(int a,string b) { this.a = a; this.b = b; } public Animal() { } public void Run() { Console.WriteLine("123123213213"); } public static void Sing() { Console.WriteLine("kkkkkkkkkkkk"); } public static string Sing2() { return "xxxxxx"; } } public class Cat : Animal { public int ba; public string bb; public Cat(int a,string b) { this.ba = a; this.bb = b; } }}
阅读全文
0 0
- 反射_程序集_额外补充
- 反射_程序集_额外补充2(将"123"转"壹贰叁"的stringbuilder打包成程序集类库的方法)
- 反射_程序集
- 反射_程序集_打包库文件_引用库文件
- 反射_
- 反射_程序集_版本转换的两种方法(.Net Framework的版本)
- 【web++_第三阶最后四集_补充】
- 反射_暴力反射
- 反射_反射概述
- Guice笔记_补充
- 黑马程序员_补充
- 人大复印资料处理程序_补充篇
- 多线程2_补充_小记
- 黑马程序员_反射
- 黑马程序员_反射
- 黑马程序员_反射
- 黑马程序员_反射
- 笔记_反射
- Windows批处理.bat检测是否安装某些软件
- 线性神经网络在Matlab中实现
- Android 沉浸式状态栏的三种实现方式
- Dlib库介绍(一)
- BigDecimal加减乘除运算
- 反射_程序集_额外补充
- MySQL分区表
- 浮动原理及清浮动笔记
- EasyDSS高性能流媒体服务器前端重构(六)- webpack-dev-server 支持手机端访问
- 字符串匹配问题解决方案之一KMP算法
- 图片标注工具LabelImg使用教程
- register_chrdev & unregister_chrdev
- HTML
- RpgMakerMV源码解析(1)-输入管理