当前位置:网站首页>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();
}
}
}
边栏推荐
- 如何安装dosbox(pycharm详细安装教程)
- qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
- 向量点积(Dot Product),向量叉积(Cross Product)
- 新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
- 重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
- 读博一年后对机器学习工程的思考
- 8月份的.NET Conf 活动 专注于 .NET MAUI
- 高效时代,电商运营如何靠RPA快速提效?
- HikariCP数据库连接池,太快了!
- This article takes you to understand the commonly used models and frameworks of recommender systems
猜你喜欢

Long battery life or safer?Seal and dark blue SL03 comparison shopping guide

HikariCP数据库连接池,太快了!

干货|如何在海量文件系统中选择合适自己的文件系统

Spearman's correlation coefficient

typeinfo类型支持库学习

Application scenarios of js anti-shake function and function throttling

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

The realization of the list

DVWA 通关记录 2 - 命令注入 Command Injection

日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
随机推荐
Implementation of mysql connection pool
logo 图标(php图片加文字水印)
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
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
yolov7创新点
wireshark的安装教程(暖气片安装方法图解)
Unknown content monitoring
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
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
php组件漏洞
R language ggplot2 visualization: based on the fill parameter and shape parameter in the aes function, custom draw a grouped line chart and add data points (scatter points), use the legend.position fu
软件测试与质量 之白盒测试
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
RPA助你玩转抖音,开启电商运营新引擎
后管实现面包屑功能
众城优选系统开发功能
Use the scrapy to climb to save data to mysql to prevent repetition
读博一年后对机器学习工程的思考
Application scenarios of js anti-shake function and function throttling
Naive Bayesian Method of Li Hang's "Statistical Learning Methods" Notes