C#特性 - 译
https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/concepts/attributes/
Attributes (C#)
特性 (C#)
metadata
元數據
declarative information
聲明性信息
assemblies
程序集
types
類型
methods
方法
properties
屬性
so forth
等等
program entity
程序實體
is associated with
和…聯系在一起;與…有關
?
at run time
在運行時
a technique called reflection
一項叫反射的技術
add metadata to your program
添加元數據到程序
.NET assemblies
.NET 程序集
a specified set of metadata
一組指定的元數據
types and type members
類型和類型成員
custom attributes
自定義特性
smaller program elements
較小的程序元素
classes and properties.
類和屬性
in the same way
adv.?? ?同樣
methods and properties
方法和屬性
?
be placed on
附加到
declaration
聲明
specify an attribute by placing the name of the attribute enclosed in square brackets ([])
通過用方括號 ([]) 將特性名稱括起來
square brackets
n:方括號
?
?
使用特性,可以有效地將元數據或聲明性信息與代碼(程序集、類型、方法、屬性等)相關聯。?
特性是指類似如下代碼;
[Serializable]
public class SampleClass
{
? ? // Objects of this type can be serialized.
}
[Conditional("DEBUG"), Conditional("TEST1")]
void TraceMethod()
{
? ? // ...
}
總結
- 上一篇: 初次使用PyCharm
- 下一篇: 快速实现dNet三层架构项目图解