当前位置:网站首页>c#高级编程-特性篇
c#高级编程-特性篇
2022-06-13 07:02:00 【万年之光】
特性
1.自定义特性类的定义
自定义特性类定义时类名后缀必须为Attribute,还需要继承于Attribute类,而且必须要指定其应用范围,如下代码所示:
[AttributeUsage(AttributeTargets.Class)]//作用于类
class sealed UIAttribute:Attribute
{
public int number;
}
2.特性如何拿到
通过反射去拿到(反射一般为类、文件的读取),如下所示:
[UI(number=100)]
class Fk{
}
void Main()//这里模仿c++的main函数写法,无需注意
{
UIAttribute[] s = (UIAttribute[])t.GetCustomAttributes(typeof(UIAttribute), false);
//FKAttribute[] s = t.GetCustomAttributes(typeof(FKAttribute), false) as FKAttribute[];
foreach(var s1 in s) {
Console.WriteLine("fk"+s1.number);
}
}
边栏推荐
- Tidb statistics
- 上位机开发(固件下载软件之编码调试)
- 髋关节MR详细图谱(转载)
- Ffmpeg compressed video.
- 2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
- Xuanwu cloud technology passed the listing hearing: the performance fluctuated significantly, and chenyonghui and other three were the controlling shareholders
- 对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
- Micro isolation (MSG)
- Byte (nine)
- 【RS-422与RS-485】RS-422与RS-485串行接口标准
猜你喜欢

Uploading and retrieving stored images in localstorage

学习Mysql基础第一天

10 Honest Facts I Want To Share With All Junior Developers

怎么写出一份令人惊叹的设计文档?

JS case Xiaomi second kill countdown New Year Countdown

Upper computer development (detailed design of firmware download software)

YOLOv5解析 | 参数与性能指标

Intelligent entertainment has developed steadily, and jinglianwen technology provides data collection and labeling services

Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge

The innovative public platoon mode team invites users to split, beautiful every second, and links the 2+1 new business model
随机推荐
Department store center supply chain management system
Is it safe to open an account online in Hangzhou?
通过函数seaborn.cubehelix_palette生成顺序调色板
如何使用望友DFM軟件進行冷板分析
MySQL系列之分库分表学习笔记
Smart finance is upgraded again, and jinglianwen technology provides data collection and labeling services
JS case Xiaomi second kill countdown New Year Countdown
Normalizing y-axis in histograms in R ggplot to proportion
FSM状态机
ISIS的vsys(虚拟系统)
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
New Taishan crowdfunding business diversion fission growth model in 2022
【RS-422与RS-485】RS-422与RS-485串行接口标准
Jinglianwen Technology: current situation and solutions of data acquisition and labeling industry
Select all select none JS code implementation
Vsys of Isis (virtual system)
[system analysis and design] college student association management system
Do you want to carry out rapid steel mesh design and ensure the quality of steel mesh? Look here
The innovative public platoon mode team invites users to split, beautiful every second, and links the 2+1 new business model
Jinglianwen technology provides a one-stop smart home data acquisition and labeling solution