- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
qr code generator vb.net Building a Hierarchy of Exception Derived Types in Visual Studio .NET
Building a Hierarchy of Exception Derived Types Drawing ANSI/AIM Code 39 In VS .NET Using Barcode generator for ASP.NET Control to generate, create Code 39 Full ASCII image in ASP.NET applications. www.OnBarcode.comBar Code Creation In VS .NET Using Barcode encoder for ASP.NET Control to generate, create barcode image in ASP.NET applications. www.OnBarcode.comThe ExceptionTree sample application (source code shown below) displays all classes that are ultimately derived from System.Exception. However, I wanted to examine types in several assemblies to produce this tree. To accomplish this, the application must explicitly load all the assemblies whose types I want to consider. This is the job of the application s LoadAssemblies method. After loading all the assemblies, the application gets an array of all the AppDomain s assemblies. Then I get an array for all types defined in each assembly. For each type, I check its base type by querying Type s BaseType property. If the Type returned is System.Exception, this type is an exception type. If the Type returned is System.Object, the type isn t an exception type. If the Type returned isn t either of these types, I check the base type s type recursively until I find Exception or Object. The following code is for the ExceptionTree application. The output from this application is shown in 18 (page 408), so I won t display it here. Code 3/9 Generator In Visual C#.NET Using Barcode generation for Visual Studio .NET Control to generate, create Code 39 image in .NET applications. www.OnBarcode.comCode 3/9 Drawer In VS .NET Using Barcode generation for .NET Control to generate, create USS Code 39 image in .NET framework applications. www.OnBarcode.comusing using using using System; System.Text; System.Reflection; System.Collections; Code 3 Of 9 Creation In Visual Basic .NET Using Barcode encoder for .NET Control to generate, create Code 3 of 9 image in .NET applications. www.OnBarcode.comLinear Barcode Printer In .NET Using Barcode creation for ASP.NET Control to generate, create Linear 1D Barcode image in ASP.NET applications. www.OnBarcode.comclass App { static void Main() { // Explicitly load the assemblies that I want to reflect over. LoadAssemblies(); // Initialize the counters and the exception type list. Int32 totalTypes = 0, totalExceptionTypes = 0; ArrayList exceptionTree = new ArrayList(); // Iterate through all assemblies loaded in this AppDomain. foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) { // Iterate through all types defined in this assembly. foreach (Type t in a.GetTypes()) { totalTypes++; // Ignore type if not a public class. if (!t.IsClass || !t.IsPublic) continue; // Build a string of the type s derivation hierarchy. StringBuilder typeHierarchy = PDF 417 Creator In .NET Using Barcode generator for ASP.NET Control to generate, create PDF 417 image in ASP.NET applications. www.OnBarcode.comBarcode Generator In Visual Studio .NET Using Barcode encoder for ASP.NET Control to generate, create barcode image in ASP.NET applications. www.OnBarcode.comnew StringBuilder(t.FullName, 5000); // Assume that the type isn t an Exception derived type. Boolean derivedFromException = false; // See if System.Exception is a base type of this type. Type baseType = t.BaseType; while ((baseType != null) && !derivedFromException) { // Append the base type to the end of the string. typeHierarchy.Append(" " + baseType); derivedFromException = (baseType == typeof(System.Exception)); baseType = baseType.BaseType; } // No more bases and not Exception derived, so try next type. if (!derivedFromException) continue; // I found an Exception derived type. totalExceptionTypes++; // For this Exception derived type, reverse the order // of the types in the hierarchy. String[] h = typeHierarchy.ToString().Split( ); Array.Reverse(h); // Build a new string with the hierarchy in order // from Exception > Exception derived type. // Add the string to the list of Exception types. exceptionTree.Add(String.Join(" ", h, 1, h.Length 1)); } } // Sort the Exception types together in order of their hierarchy. exceptionTree.Sort(); // Display the Exception tree. foreach (String s in exceptionTree) { // For this Exception type, split its base types apart. String[] x = s.Split( ); // Indent based on the number of base types, // and then show the most derived type. Console.WriteLine( new String( , 3 * x.Length) + x[x.Length 1]); } // Show the final status of the types considered. Console.WriteLine("\n > Of {0} types, {1} are " + "derived from System.Exception.", totalTypes, totalExceptionTypes); Console.ReadLine(); } static void LoadAssemblies() { String[] assemblies = { "System, "System.Data, "System.Design, "System.DirectoryServices, "System.Drawing, "System.Drawing.Design, Draw EAN / UCC - 14 In .NET Using Barcode generation for ASP.NET Control to generate, create EAN128 image in ASP.NET applications. www.OnBarcode.comECC200 Printer In .NET Framework Using Barcode creation for ASP.NET Control to generate, create Data Matrix ECC200 image in ASP.NET applications. www.OnBarcode.comPublicKeyToken={0}", PublicKeyToken={0}", PublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={1}", UCC - 12 Printer In .NET Framework Using Barcode creator for ASP.NET Control to generate, create UPC-A Supplement 5 image in ASP.NET applications. www.OnBarcode.comISSN - 13 Generation In .NET Framework Using Barcode generation for ASP.NET Control to generate, create ISSN - 13 image in ASP.NET applications. www.OnBarcode.com"System.EnterpriseServices, "System.Management, "System.Messaging, "System.Runtime.Remoting, "System.Security, "System.ServiceProcess, "System.Web, "System.Web.RegularExpressions, "System.Web.Services, "System.Windows.Forms, "System.Xml, }; 2D Barcode Creator In Visual Studio .NET Using Barcode printer for .NET Control to generate, create Matrix Barcode image in .NET framework applications. www.OnBarcode.comCode 128 Code Set B Generation In .NET Framework Using Barcode generation for Reporting Service Control to generate, create ANSI/AIM Code 128 image in Reporting Service applications. www.OnBarcode.comPublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={0}", PublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={1}", PublicKeyToken={0}", PublicKeyToken={0}", Paint UPCA In Java Using Barcode drawer for BIRT reports Control to generate, create UPCA image in Eclipse BIRT applications. www.OnBarcode.comGenerate Bar Code In None Using Barcode drawer for Font Control to generate, create bar code image in Font applications. www.OnBarcode.comString EcmaPublicKeyToken = "b77a5c561934e089"; String MSPublicKeyToken = "b03f5f7f11d50a3a"; // Get the version of the assembly containing System.Object. // I ll assume the same version for all the other assemblies. Version version = typeof(System.Object).Assembly.GetName().Version; // Explicitly load the assemblies that I want to reflect over. foreach (String a in assemblies) { String AssemblyIdentity = String.Format(a, EcmaPublicKeyToken, MSPublicKeyToken) + ", Culture=neutral, Version=" + version; Assembly.Load(AssemblyIdentity); } } } Create USS-128 In None Using Barcode drawer for Font Control to generate, create GS1-128 image in Font applications. www.OnBarcode.comPDF417 Maker In None Using Barcode encoder for Office Excel Control to generate, create PDF 417 image in Office Excel applications. www.OnBarcode.comDraw Data Matrix In Java Using Barcode generator for Java Control to generate, create ECC200 image in Java applications. www.OnBarcode.comEAN13 Creator In Visual C#.NET Using Barcode generation for .NET framework Control to generate, create UPC - 13 image in VS .NET applications. www.OnBarcode.com |
|