Post by "KevinShan", 02-27-2008, 13:23
-----------------------------------------------------
今天看到一个博客里提到了反射的用法,没想到可以这样用:你能使用反射通过在前缀后放一个"*"查找包含前缀的成员:
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
- MemberInfo[] members = typeof(A).GetMember("hidden*",
- BindingFlags.NonPublic | BindingFlags.Instance);
- // members now contains three members: hiddenFlag1, hiddenFlag2 and hiddenMethod
- //
- public class A
- {
- private bool hiddenFlag1;
- private bool hiddenFlag2;
- private void hiddenMethod()
- {
- }
- private void reallyHiddenMethod()
- {
- }
- }
复制代码 转自http://www.cnblogs.com/yangjie5188/archive/2008/02/22/1078188.html
经测试,确实可以如此。 |
|