当前位置:网站首页>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 love-hate relationship between C language volatile keyword, inline assembly volatile and compiler
- 重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
- node封装一个图片拼接插件
- php组件漏洞
- 读博一年后对机器学习工程的思考
- currentstyle 织梦_dede currentstyle属性完美解决方案
- qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
- 适配器模式适配出栈和队列及优先级队列
- 软件测试之发现和解决bug
- npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
猜你喜欢
随机推荐
qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
List-based queuing and calling system
AutoJs学习-实现谢尔宾斯基三角
node封装一个图片拼接插件
李航《统计学习方法》笔记之朴素贝叶斯法
高效时代,电商运营如何靠RPA快速提效?
【新版干货书】深度伪造 (DeepFakes):创造,检测和影响
EdrawMax Crack,多合一的图表应用程序
npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
转转反爬攻防战
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
Implementation of mysql connection pool
Application scenarios of js anti-shake function and function throttling
单词接龙 II
iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?
Naive Bayesian Method of Li Hang's "Statistical Learning Methods" Notes
QT专题:自定义部件
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
1对1视频源码——快速实现短视频功能提升竞争力
第十七章 Excel操作








