反射也可以这样?
今天看到一个博客里提到了反射的用法,没想到可以这样用:你能使用反射通过在前缀后放一个"*"查找包含前缀的成员:
1MemberInfo[] members = typeof(A).GetMember("hidden*",
2 BindingFlags.NonPublic | BindingFlags.Instance);
3
4// members now contains three members: hiddenFlag1, hiddenFlag2 and hiddenMethod
5
6//
7
8public class A
9{
10 private bool hiddenFlag1;
11 private bool hiddenFlag2;
12
13 private void hiddenMethod()
14 {
15 }
16
17 private void reallyHiddenMethod()
18 {
19 }
20}
2 BindingFlags.NonPublic | BindingFlags.Instance);
3
4// members now contains three members: hiddenFlag1, hiddenFlag2 and hiddenMethod
5
6//
7
8public class A
9{
10 private bool hiddenFlag1;
11 private bool hiddenFlag2;
12
13 private void hiddenMethod()
14 {
15 }
16
17 private void reallyHiddenMethod()
18 {
19 }
20}