反射和特性-Type类

元数据与反射

1.jpg

Type类

2.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
namespace ConsoleApp7
{
class MyClass
{
public int intIndex1;
public float floatIndex1;
private int intIndex2;

public int prop1
{
get { return 1; }
}

private int prop2
{
get { return 2; }
}

public void func1(){}

private void func2(){}
}
}
-------------------------------------------------------------------------------------------------------------------------
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
//每一个类对应一个type对象,这个type对象存储了这个类有哪些方法与哪些数据与哪些成员。
MyClass myClass = new MyClass();//一个类中的数据是存储在对象中的,但是type对象只存储类的成员。

Type type = myClass.GetType();//通过对象获取这个对象所属类的type对象。
Console.WriteLine(type.Name);//获取类名。
Console.WriteLine(type.Namespace);//获取类的名字。
Console.WriteLine(type.Assembly);//获取类的程序集。

Console.WriteLine("type.GetFields()");
//Returns all the public fields of the current System.Type.
FieldInfo[] FieldArrays = type.GetFields();
foreach (FieldInfo info in FieldArrays)
{
Console.WriteLine(info.Name);
}

Console.WriteLine("type.GetProperties()");
//Returns all the public properties of the current System.Type.
PropertyInfo[] PropertyArrays = type.GetProperties();
foreach (PropertyInfo info in PropertyArrays)
{
Console.WriteLine(info.Name);
}

Console.WriteLine("type.GetMethods()");
//Returns all the public methods of the current System.Type.
MethodInfo[] MethodArrays = type.GetMethods();
foreach (MethodInfo info in MethodArrays)
{
Console.WriteLine(info.Name);
}

Console.ReadKey();
}
}
}
-------------------------------------------------------------------------------------------------------------------------
输出:
MyClass
ConsoleApp7,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null
type.GetFields()
intIndex1
floatIndex1
type.GetProperties()
prop1
type.GetMethods()
get_prop1
func1
GetType
ToString
Equals
GetHashCode

反射和特性Assembly程序集类

3.jpg

Obsolete特性

4.jpg

Conditional特性

5.jpg

调用者信息特性

6.jpg

DebuggerStepThrough特性

7.jpg

其他预定义特性

8.jpg

什么是特性

9.jpg
10.jpg

创建自定义特性

11.jpg
12.jpg

正则表达式

13.jpg

正则表达式的组成

14.jpg

常用的操作正则表达式的方法和委托

15.jpg

静态方法Match

16.jpg

静态方法Matches

17.jpg

Replace函数

18.jpg

静态方法Split

19.jpg

@符号

20.jpg

定位元字符

21.jpg
22.jpg

基本语法元字符

23.jpg
24.jpg

反义字符

25.jpg
26.jpg

重复描述字符

27.jpg
28.jpg

择一匹配符

29.jpg
30.jpg
31.jpg

对正则表达式进行分组

32.jpg