// Decompiled by Salamander version 1.0.9 // Copyright 2002 Remotesoft Inc. All rights reserved. // http://www.remotesoft.com/salamander using System; using System.Collections; using System.IO; using System.Reflection; using System.Text; class FindType { private const int SHOW_INTERFACES = 1; private const int SHOW_FIELDS = 2; private const int SHOW_PROPERTIES = 4; private const int SHOW_EVENTS = 8; private const int SHOW_METHODS = 16; private const int SHOW_MODULE_INFO = 32; private IndentedWriter myVerboseWriter = new IndentedWriter(); private IndentedWriter myWriter = new IndentedWriter(); private bool exactMatchOnly = false; private bool recurseTypes = false; private bool matchOnlyNamespace = false; private bool wideSearch = false; private int showOptions = 0; private ArrayList myClassList = new ArrayList(); private ArrayList DirList = new ArrayList(); public bool ExactMatchOnly { get { return exactMatchOnly; } set { exactMatchOnly = value; } } public bool RecurseTypes { get { return recurseTypes; } set { recurseTypes = value; } } public bool MatchOnlyNamespace { get { return matchOnlyNamespace; } set { matchOnlyNamespace = value; } } public bool WideSearch { get { return wideSearch; } set { wideSearch = value; } } public bool VerbosePrint { get { return myVerboseWriter.Print; } set { myVerboseWriter.Print = value; } } public bool ShowInterfaces { get { return (showOptions & 1) == 0 == false; } set { if (value) { showOptions |= 1; } else { showOptions &= -2; } } } public bool ShowFields { get { return (showOptions & 2) == 0 == false; } set { if (value) { showOptions |= 2; } else { showOptions &= -3; } } } public bool ShowProperties { get { return (showOptions & 4) == 0 == false; } set { if (value) { showOptions |= 4; } else { showOptions &= -5; } } } public bool ShowEvents { get { return (showOptions & 8) == 0 == false; } set { if (value) { showOptions |= 8; } else { showOptions &= -9; } } } public bool ShowMethods { get { return (showOptions & 16) == 0 == false; } set { if (value) { showOptions |= 16; } else { showOptions &= -17; } } } public bool ShowModuleInfo { get { return (showOptions & 32) == 0 == false; } set { if (value) { showOptions |= 32; } else { showOptions &= -33; } } } public void Search() { if (myClassList.Count != 0) { for (int i = 0; i < myClassList.Count; i++) { Search((String)myClassList[i]); } } } public void Search(string theSearchString) { Assembly testAssy = Assembly.Load("mscorlib.dll"); myVerboseWriter.WriteLine("Searching System Libraries"); string dirFrameworks = Path.GetDirectoryName(testAssy.Location); ArrayList l = new ArrayList(); BuildDLLFileList(dirFrameworks, l); for (int j = 0; j < l.Count; j++) { Search(theSearchString, (String)l[j]); } myVerboseWriter.WriteLine("Searching the current directory..."); l = new ArrayList(); BuildDLLFileList(".", l); for (int i = 0; i < l.Count; i++) { Search(theSearchString, (String)l[i]); } object[] dir = DirList.ToArray(); for (int j2 = 0; j2 < (int)dir.Length; j2++) { myVerboseWriter.WriteLine("Searching directory {0}...", new object[]{dir[j2]}); l = new ArrayList(); BuildDLLFileList((String)dir[j2], l); for (int k = 0; k < l.Count; k++) { Search(theSearchString, (String)l[k]); } } } public void Search(string theSearchString, string theModule) { try { Assembly a = Assembly.LoadFrom(theModule); Module[] m = a.GetModules(); theSearchString = theSearchString.ToUpper(); for (int j = 0; j < (int)m.Length; j++) { myVerboseWriter.WriteLine("Searching Module {0}", new object[]{theModule}); if (m != null) { Type[] types = m[j].GetTypes(); for (int i = 0; i < (int)types.Length; i++) { Type curType = types[i]; string name = curType.FullName.ToUpper(); if (ExactMatchOnly) { if (name == theSearchString) { DumpType(curType); } } else if (MatchOnlyNamespace) { if (curType.Namespace != null && curType.Namespace.ToUpper() == theSearchString) { DumpType(curType); } } else if (WideSearch) { if (curType.Namespace.ToUpper().IndexOf(theSearchString) != -1) { DumpType(curType); } } else if (name == theSearchString) { 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; for (int i2 = 0; i2 < (int)loadedTypes.Length; i2++) { if (loadedTypes[i2] == null) { exceptionCount++; } } } catch (FileNotFoundException fnfe) { myVerboseWriter.WriteLine(fnfe.Message); } catch { } } 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 directory, ArrayList list) { try { if (Directory.Exists(directory)) { string[] e = Directory.GetFiles(directory, "*.dll"); for (int i = 0; i < (int)e.Length; i++) { list.Add(e[i]); } } else { myVerboseWriter.WriteLine("Directory [{0}] does not exist!", new object[]{directory}); } } 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 str2 = str; return str2; } private void DumpType(Type aType) { Type baseType = aType.BaseType; myWriter.WriteLine("{0,-10} {1}", new object[]{GetTypeDescription(aType), aType}); if (ShowModuleInfo) { myWriter.WriteLine("{0,-10} {1}", new object[]{"Module:", aType.Module.FullyQualifiedName}); } DumpInterfaces(aType); DumpFields(aType); DumpProperties(aType); DumpEvents(aType); DumpMethods(aType); if (RecurseTypes) { myWriter.WriteLine(); } if (RecurseTypes && baseType != null) { myWriter.PushIndent(); myVerboseWriter.PushIndent(); DumpType(baseType); myWriter.PopIndent(); myVerboseWriter.PopIndent(); } } private void DumpInterfaces(Type aType) { if (ShowInterfaces) { Type[] info = aType.GetInterfaces(); if ((int)info.Length != 0) { myWriter.WriteLine("{0} {1}", new object[]{"# Interfaces:", (int)info.Length}); for (int i = 0; i < (int)info.Length; i++) { myWriter.PushIndent(); myWriter.WriteLine("interface {0}", new object[]{info[i].FullName}); 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 ((int)pInfo.Length != 0) { PropertyInfo curInfo = null; for (int i = 0; i < (int)pInfo.Length; i++) { curInfo = pInfo[i]; if (curInfo.DeclaringType == aType) { found = true; string flags = null; if (curInfo.CanRead && curInfo.CanWrite) { 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 ((int)eInfo.Length != 0) { for (int i = 0; i < (int)eInfo.Length; 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 ((int)info.Length != 0) { for (int i = 0; i < (int)info.Length; 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 ((int)mInfo.Length != 0) { for (int i = 0; i < (int)mInfo.Length; i++) { if (mInfo[i].DeclaringType == aType && !mInfo[i].IsSpecialName) { 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)"); } } } }