?? reflector.cs
字號:
/******************************************************************************
Module: Reflector.cs
Notices: Copyright (c) 2002 Jeffrey Richter
******************************************************************************/
// Define either V1, V2, or V3 to match the example from the book
#define V3
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Reflection;
///////////////////////////////////////////////////////////////////////////////
class App {
static void Main() {
#if V1 || V3
Assembly assem = Assembly.GetExecutingAssembly();
Reflector.ReflectOnAssembly(assem);
#endif
#if V2
foreach (Assembly assem in
AppDomain.CurrentDomain.GetAssemblies()) {
Reflector.ReflectOnAssembly(assem);
}
#endif
Console.WriteLine("Press <Enter> to exit.");
Console.ReadLine();
}
}
///////////////////////////////////////////////////////////////////////////////
public class Reflector {
public static void ReflectOnAssembly(Assembly assem) {
WriteLine(0, "Assembly: {0}", assem);
// Find Modules
foreach (Module m in assem.GetModules()) {
WriteLine(1, "Module: {0}", m);
// Find Types
foreach (Type t in m.GetTypes()) {
WriteLine(2, "Type: {0}", t);
// Find Members
#if V1 || V2
foreach (MemberInfo mi in t.GetMembers())
WriteLine(3, "{0}: {1}", mi.MemberType, mi);
#endif
#if V3
BindingFlags bf = BindingFlags.DeclaredOnly |
BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static;
foreach (MemberInfo mi in t.GetMembers(bf))
WriteLine(3, "{0}: {1}", mi.MemberType, mi);
#endif
}
}
}
private static void WriteLine(Int32 indent, String format,
params Object[] args) {
Console.WriteLine(new String(' ', 3 * indent) + format, args);
}
}
///////////////////////////////////////////////////////////////////////////////
class SomeType {
public class InnerType {}
public Int32 SomeField = 0;
private static String goo = null;
private void SomeMethod() { }
private TimeSpan SomeProperty {
get { return new TimeSpan(); }
set { }
}
public static event System.Threading.ThreadStart SomeEvent;
private void NoCompilerWarnings() {
// This code is here just to make the compiler warnings go away
SomeEvent.ToString();
goo.ToString();
}
}
//////////////////////////////// End of File //////////////////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -