当前位置:网站首页>c#反射和特性
c#反射和特性
2022-08-02 09:51:00 【zzyzxb】
1、关于类型的反射示例
static void Main(string[] args)
{
string s = "hello";
Type t1 = s.GetType();
Console.WriteLine(t1.FullName);
Type t2 = Type.GetType("System.String", false, true);
Console.WriteLine(t2.FullName);
Type t3 = typeof(string);
Console.WriteLine(t3.FullName);
Console.ReadLine();
}
2、关于方法的反射示例
static void Main(string[] args)
{
string s = "hello";
Type t1 = s.GetType();
Console.WriteLine(t1.FullName);
Type t2 = Type.GetType("System.String", false, true);
Console.WriteLine(t2.FullName);
Type t3 = typeof(string);
Console.WriteLine(t3.FullName);
Console.WriteLine("*********************************************");
//GetMethods(t1);
Console.WriteLine("Copy method: {0}", t1.GetMethod("Copy"));
GetMethods(t1, BindingFlags.Public & BindingFlags.Instance);
//GetFields(), GetProperties();
Console.ReadLine();
}
public static void GetMethods(Type t, BindingFlags flags)
{
MethodInfo[] methodInfos = t.GetMethods(flags);
foreach (MethodInfo method in methodInfos)
{
Console.WriteLine(method.Name);
}
}
3、条件预处理指令
//#define DEBUG
//#undef DEBUG
#define TRACE
using System;
using System.Diagnostics;
using System.Reflection;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
#if (DEBUG)
{
Console.WriteLine("Debugging is enabled");
}
#elif(TRACE)
{
Console.WriteLine("Tracing is enabled");
}
#else
{
Console.WriteLine("Release is enabled");
}
#endif
Console.WriteLine("hello");
Console.ReadLine();
}
}
}
边栏推荐
- 周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...
- Re23:读论文 How Does NLP Benefit Legal System: A Summary of Legal Artificial Intelligence
- Linux system uninstall, install, upgrade, migrate clickHouse database
- 身为程序猿——谷歌浏览器的这些骚操作你真的废吗!【熬夜整理&建议收藏】[通俗易懂]
- QT专题:自定义部件
- Supervised learning of Li Hang's "Statistical Learning Methods" Notes
- R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化水平柱状图(条形图)、使用orientation参数设置柱状图转置为条形图
- 日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
- R language time series data arithmetic operation: use the log function to log the time series data, and use the diff function to calculate the successive difference of the logarithmic time series data
- Linux系统卸载,安装,升级,迁移clickHouse数据库
猜你喜欢

QT专题:组合会话框和文本编辑器

Re23:读论文 How Does NLP Benefit Legal System: A Summary of Legal Artificial Intelligence

软件测试与质量 之白盒测试

mysql连接池的实现

AutoJs学习-AES加解密

Use the scrapy to climb to save data to mysql to prevent repetition

百战RHCE(第四十七战:运维工程师必会技-Ansible学习2-Ansible安装配置练习环境)

日元疲软令游戏机在日本变身“理财产品”:黄牛大赚

node制作一个视频帧长图生成器

Spearman's correlation coefficient
随机推荐
百战RHCE(第四十六战:运维工程师必会技-Ansible学习1-基础知识讲解)
Mistakes in Brushing the Questions 1-Implicit Conversion and Loss of Precision
The realization of the list
全新荣威RX5,27寸大屏吸引人,安全、舒适一个不落
Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
练习16-两道模拟题
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化堆叠的柱状图(stacked bar plot)、lab.pos参数指定柱状图的数值标签的位置,lab.col参数指定数值标
Chapter 15 Generics
qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
Verilog的随机数系统任务----$random
Pytorch的LSTM参数解释
The ggbarplot function of the R language ggpubr package visualizes the grouped histogram, sets the add parameter to mean_se to visualize the histogram of the mean values of different levels and adds
The perceptron perceptron of Li Hang's "Statistical Learning Methods" notes
理解JS的三座大山
刷题错题录1-隐式转换与精度丢失
The R language uses the rollapply function in the zoo package to apply the specified function to the time series in a rolling manner and the window moves, and set the align parameter to specify that t
EdrawMax Crack,多合一的图表应用程序
【技术分享】OSPFv3基本原理
李航《统计学习方法》笔记之朴素贝叶斯法
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the stacked bar plot, the lab.pos parameter specifies the position of the numerical label of the bar cha