当前位置:网站首页>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();
}
}
}
边栏推荐
- 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
- Getting Started with SCM from Scratch (1): Summary of Background Knowledge
- npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
- logo 图标(php图片加文字水印)
- The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit
- 百战RHCE(第四十七战:运维工程师必会技-Ansible学习2-Ansible安装配置练习环境)
- 软件测试X模型
- net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
- 你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
- 2022.7.25-7.31 AI行业周刊(第108期):值钱比赚钱更重要
猜你喜欢
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
基于列表的排队与叫号系统
第十六章 协程
全新荣威RX5,27寸大屏吸引人,安全、舒适一个不落
适配器模式适配出栈和队列及优先级队列
DVWA 通关记录 2 - 命令注入 Command Injection
In the whole development of chi V853 board tried to compile QT test
List-based queuing and calling system
理解JS的三座大山
1对1视频源码——快速实现短视频功能提升竞争力
随机推荐
要长续航还是更安全?海豹与深蓝SL03对比导购
sqlmap安装教程用w+r打开(sqlyog安装步骤)
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化堆叠的柱状图(stacked bar plot)、lab.pos参数指定柱状图的数值标签的位置,lab.col参数指定数值标
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
The realization of the list
ConvNeXt论文及实现
Verilog的随机数系统任务----$random
AlterNET Studio用户界面设计功能扩展
TimerTask(addin timer语音)
Facebook自动化数据分析方案,广告投放省心省力
周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...
logo 图标(php图片加文字水印)
MySql千万级分页优化,快速插入千万数据方法
QT专题:事件机制event基础篇
RPA助你玩转抖音,开启电商运营新引擎
List-based queuing and calling system
使用scrapy 把爬到的数据保存到mysql 防止重复
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
mysql进阶(二十一)删除表数据与数据库四大特性
QT专题:组合会话框和文本编辑器