using Microsoft.VisualBasic.CompilerServices; using System; using System.Collections; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; class FindType { private int SHOW_INTERFACES; private int SHOW_FIELDS; private int SHOW_PROPERTIES; private int SHOW_EVENTS; private int SHOW_METHODS; private int SHOW_MODULE_INFO; private IndentedWriter myVerboseWriter; private IndentedWriter myWriter; private bool exactMatchOnlyField; private bool recurseTypesField; private bool matchOnlyNamespaceField; private bool wideSearchField; private int showOptions; private ArrayList myClassList; private ArrayList DirList; public bool ExactMatchOnly { get { return exactMatchOnlyField; } set { exactMatchOnlyField = value; } } public bool RecurseTypes { get { return recurseTypesField; } set { recurseTypesField = value; } } public bool MatchOnlyNamespace { get { return matchOnlyNamespaceField; } set { matchOnlyNamespaceField = value; } } public bool WideSearch { get { return wideSearchField; } set { wideSearchField = value; } } public bool ShowInterfaces { get { return (showOptions & SHOW_INTERFACES) == 0 == false; } set { if (value) { showOptions |= SHOW_INTERFACES; } else { showOptions &= ~SHOW_INTERFACES; } } } public bool ShowMethods { get { return (showOptions & SHOW_METHODS) == 0 == false; } set { if (value) { showOptions |= SHOW_METHODS; } else { showOptions &= ~SHOW_METHODS; } } } public bool ShowFields { get { return (showOptions & SHOW_FIELDS) == 0 == false; } set { if (value) { showOptions |= SHOW_FIELDS; } else { showOptions &= ~SHOW_FIELDS; } } } public bool ShowProperties { get { return (showOptions & SHOW_PROPERTIES) == 0 == false; } set { if (value) { showOptions |= SHOW_PROPERTIES; } else { showOptions &= ~SHOW_PROPERTIES; } } } public bool ShowEvents { get { return (showOptions & SHOW_EVENTS) == 0 == false; } set { if (value) { showOptions |= SHOW_EVENTS; } else { showOptions &= ~SHOW_EVENTS; } } } public bool ShowModuleInfo { get { return (showOptions & SHOW_MODULE_INFO) == 0 == false; } set { if (value) { showOptions |= SHOW_MODULE_INFO; } else { showOptions &= ~SHOW_MODULE_INFO; } } } public bool VerbosePrint { get { return myVerboseWriter.Print; } set { myVerboseWriter.Print = value; } } public FindType() { SHOW_INTERFACES = 1; SHOW_FIELDS = 2; SHOW_PROPERTIES = 4; SHOW_EVENTS = 8; SHOW_METHODS = 16; SHOW_MODULE_INFO = 32; myVerboseWriter = new IndentedWriter(); myWriter = new IndentedWriter(); exactMatchOnlyField = false; recurseTypesField = false; matchOnlyNamespaceField = false; wideSearchField = false; showOptions = 0; myClassList = new ArrayList(); DirList = new ArrayList(); } public void Search() { if (myClassList.Count != 0) { int _Vb_t_i4_0 = myClassList.Count - 1; for (int i = 0; i <= _Vb_t_i4_0; i++) { Search(StringType.FromObject(myClassList[i])); } } } public void Search(string theSearchString) { string dirFrameworks = Path.GetDirectoryName(Assembly.Load("mscorlib.dll").Location); myVerboseWriter.WriteLine("Searching System Libraries"); ArrayList l = new ArrayList(); BuildDLLFileList(dirFrameworks, l); int _Vb_t_i4_0 = l.Count - 1; for (int j = 0; j <= _Vb_t_i4_0; j++) { Search(theSearchString, StringType.FromObject(l[j])); } myVerboseWriter.WriteLine("Searching the current directory..."); l = new ArrayList(); BuildDLLFileList(".", l); int _Vb_t_i4_1 = l.Count - 1; for (int j = 0; j <= _Vb_t_i4_1; j++) { Search(theSearchString, StringType.FromObject(l[j])); } object[] dir = DirList.ToArray(); int _Vb_t_i4_2 = dir.Length - 1; for (int i = 0; i <= _Vb_t_i4_2; i++) { myVerboseWriter.WriteLine("Searching directory {0}...", new object[]{RuntimeHelpers.GetObjectValue(dir[i])}); l = new ArrayList(); BuildDLLFileList(StringType.FromObject(dir[i]), l); int _Vb_t_i4_3 = l.Count - 1; for (int j = 0; j <= _Vb_t_i4_3; j++) { Search(theSearchString, StringType.FromObject(l[j])); } } } public void Search(string theSearchString, string theModule) { try { Assembly a = Assembly.LoadFrom(theModule); Module[] m = a.GetModules(); theSearchString = theSearchString.ToUpper(); int _Vb_t_i4_0 = m.Length - 1; for (int j = 0; j <= _Vb_t_i4_0; j++) { myVerboseWriter.WriteLine("Searching Module {0}", new object[]{theModule}); if (m != null) { Type[] types = m[j].GetTypes(); int _Vb_t_i4_1 = types.Length - 1; for (int i = 0; i <= _Vb_t_i4_1; i++) { Type curType = types[i]; string name = curType.FullName.ToUpper(); if (ExactMatchOnly) { if (StringType.StrCmp(name, theSearchString, false) == 0) { DumpType(curType); } } else if (MatchOnlyNamespace) { if (curType.Namespace != null && StringType.StrCmp(curType.Namespace.ToUpper(), theSearchString, false) == 0) { DumpType(curType); } } else if (WideSearch) { if (curType.Namespace.ToUpper().IndexOf(theSearchString) != -1) { DumpType(curType); } } else if (StringType.StrCmp(name, theSearchString, false) == 0) { int oldOptions = showOptions; if (showOptions == 0) { ShowAll(); } DumpType(curType); showOptions = oldOptions; } else if (name.IndexOf(theSearchString) != -1) { DumpType(curType); } } } } } catch (ReflectionTypeLoadException rcle) { Type[] loadedTypes = rcle.Types; Exception[] exceptions = rcle.LoaderExceptions; int exceptionCount = 0; int _Vb_t_i4_2 = loadedTypes.Length - 1; for (int i2 = 0; i2 <= _Vb_t_i4_2; i2++) { if (loadedTypes[i2] == null) { exceptionCount++; } } } catch (FileNotFoundException fnfe) { myVerboseWriter.WriteLine(fnfe.Message); } catch (Exception e) { } } public void ShowAll() { ShowInterfaces = true; ShowMethods = true; ShowFields = true; ShowProperties = true; ShowEvents = true; ShowModuleInfo = true; } public void DirAdd(string dir) { DirList.Add(dir); } public void ClassAdd(string newClass) { myClassList.Add(newClass); } private void BuildDLLFileList(string dirName, ArrayList list) { try { if (Directory.Exists(dirName)) { string[] e = Directory.GetFiles(dirName, "*.dll"); int _Vb_t_i4_0 = e.Length - 1; for (int i = 0; i <= _Vb_t_i4_0; i++) { list.Add(e[i]); } } else { myVerboseWriter.WriteLine("Directory [{0}] does not exist!", new object[]{dirName}); } } catch (Exception Ex) { if (Ex.GetType() != typeof(InvalidOperationException)) { } } } private string GetTypeDescription(Type aType) { string str = null; if (aType.IsClass) { str = "class"; } if (aType.IsInterface) { str = "interface"; } if (aType.IsValueType) { str = "struct"; } if (aType.IsArray) { str = "array"; } string GetTypeDescription = str; return GetTypeDescription; } private void DumpType(Type aType) { Type baseType = aType.BaseType; object[] _Vb_t_array_0 = new object[]{GetTypeDescription(aType), aType}; myWriter.WriteLine("{0,-10} {1}", _Vb_t_array_0); if (ShowModuleInfo) { _Vb_t_array_0 = new object[]{"Module:", aType.Module.FullyQualifiedName}; myWriter.WriteLine("{0,-10} {1}", _Vb_t_array_0); } DumpInterfaces(aType); DumpFields(aType); DumpProperties(aType); DumpEvents(aType); DumpMethods(aType); if (RecurseTypes) { myWriter.WriteLine(); } if ((RecurseTypes & baseType == null == false) != 0) { myWriter.PushIndent(); myVerboseWriter.PushIndent(); DumpType(baseType); myWriter.PopIndent(); myVerboseWriter.PopIndent(); } } private void DumpInterfaces(Type aType) { if (ShowInterfaces) { Type[] info = aType.GetInterfaces(); if (info.Length != 0) { object[] _Vb_t_array_0 = new object[]{"# Interfaces:", info.Length}; myWriter.WriteLine("{0} {1}", _Vb_t_array_0); int _Vb_t_i4_0 = info.Length - 1; for (int i = 0; i <= _Vb_t_i4_0; i++) { myWriter.PushIndent(); _Vb_t_array_0 = new object[]{info[i].FullName}; myWriter.WriteLine("interface {0}", _Vb_t_array_0); if (ShowMethods) { myWriter.PushIndent(); DumpType(info[i]); myWriter.PopIndent(); } myWriter.PopIndent(); } } } } private void DumpProperties(Type aType) { if (ShowProperties) { PropertyInfo[] pInfo = aType.GetProperties(); myWriter.WriteLine("Properties"); bool found = false; if (pInfo.Length != 0) { PropertyInfo curInfo = null; int _Vb_t_i4_0 = pInfo.Length - 1; for (int i = 0; i <= _Vb_t_i4_0; i++) { curInfo = pInfo[i]; if (curInfo.DeclaringType == aType) { found = true; string flags = null; if ((curInfo.CanRead & curInfo.CanWrite) != 0) { flags = "get; set;"; } else if (curInfo.CanRead) { flags = "get"; } else if (curInfo.CanWrite) { flags = "set"; } myWriter.WriteLine(" {0,-10} \'{1}\' ", new object[]{curInfo, flags}); } } } if (!found) { myWriter.WriteLine(" (none)"); } } } private void DumpEvents(Type aType) { if (ShowEvents) { EventInfo[] eInfo = aType.GetEvents(); myWriter.WriteLine("Events:"); bool found = false; if (eInfo.Length != 0) { int _Vb_t_i4_0 = eInfo.Length - 1; for (int i = 0; i <= _Vb_t_i4_0; i++) { if (eInfo[i].DeclaringType == aType) { found = true; myWriter.WriteLine(" {0}", new object[]{eInfo[i]}); } } } if (!found) { myWriter.WriteLine(" (none)"); } } } private void DumpFields(Type aType) { if (ShowFields) { FieldInfo[] info = aType.GetFields(); myWriter.WriteLine("Fields:"); bool found = false; if (info.Length != 0) { int _Vb_t_i4_0 = info.Length - 1; for (int i = 0; i <= _Vb_t_i4_0; i++) { if (info[i].DeclaringType == aType) { myWriter.WriteLine(" {0}", new object[]{info[i]}); found = true; } } } if (!found) { myWriter.WriteLine(" (none)"); } } } private void DumpMethods(Type aType) { if (ShowMethods) { MethodInfo[] mInfo = aType.GetMethods(); myWriter.WriteLine("Methods"); bool found = false; if (mInfo.Length != 0) { int _Vb_t_i4_0 = mInfo.Length - 1; for (int i = 0; i <= _Vb_t_i4_0; i++) { if ((mInfo[i].DeclaringType == aType & mInfo[i].IsSpecialName == false) != 0) { found = true; StringBuilder modifiers = new StringBuilder(); if (mInfo[i].IsStatic) { modifiers.Append("static "); } if (mInfo[i].IsPublic) { modifiers.Append("public "); } if (mInfo[i].IsFamily) { modifiers.Append("protected "); } if (mInfo[i].IsAssembly) { modifiers.Append("internal "); } if (mInfo[i].IsPrivate) { modifiers.Append("private "); } myWriter.WriteLine(" {0} {1}", new object[]{modifiers, mInfo[i]}); } } } if (!found) { myWriter.WriteLine(" (none)"); } } } }