当前位置:网站首页>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();
}
}
}
边栏推荐
- 软件测试与质量 之白盒测试
- 众城优选系统开发功能
- 基于列表的排队与叫号系统
- HikariCP database connection pool, too fast!
- 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
- R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化堆叠的柱状图(stacked bar plot)、lab.pos参数指定柱状图的数值标签的位置,lab.col参数指定数值标
- 开源一夏 | GO语言框架中如何快速集成日志模块
- ConvNeXt论文及实现
- In the whole development of chi V853 board tried to compile QT test
- logo 图标(php图片加文字水印)
猜你喜欢

【技术分享】OSPFv3基本原理

typeinfo类型支持库学习

高效时代,电商运营如何靠RPA快速提效?

This article takes you to understand the commonly used models and frameworks of recommender systems

Facebook自动化数据分析方案,广告投放省心省力

The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit

第十六章 协程

List-based queuing and calling system

npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.

Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
随机推荐
QT专题:自定义部件
练习16-两道模拟题
node封装一个图片拼接插件
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
R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
mysql进阶(二十一)删除表数据与数据库四大特性
带你认识40G单纤双向光模块-QSFP+ BiDi光模块
AlterNET Studio用户界面设计功能扩展
Chapter 15 Generics
李航《统计学习方法》笔记之k近邻法
QT专题:事件机制event基础篇
The perceptron perceptron of Li Hang's "Statistical Learning Methods" notes
The R language uses the ggtexttable function of the ggpubr package to visualize the table data (draw the table directly or add the table data to the image), set the theme parameter to customize the fi
单词接龙 II
Spearman's correlation coefficient
HikariCP database connection pool, too fast!
Using the TCP protocol, will there be no packet loss?
打印lua内部结构的函数调用
迭代器失效问题
Use the scrapy to climb to save data to mysql to prevent repetition